Roblox 工作室脚本

问题描述 投票:0回答:1

我看了一个关于如何制作塔防游戏的教程(来自 gnomecode),我需要帮助,我停在关于如何放置塔的 6# 视频,但是当我完成脚本并检查一切似乎都很好,但是当我点击了塔名称 GUI 按钮,它开始在输出中发送垃圾邮件错误,例如

Players.Playername.PlayerGui.GameGui.GameController:96:尝试使用“Size”索引 nil

这是游戏控制器脚本(渲染部分(96行是本地y)

RunService.RenderStepped:Connect(function()
    if towerToSpawn then
        local result = MouseRaycast({towerToSpawn})
        if result and result.Instance then
            if result.Instance.Parent.Name == "TowerArea" then
                canPlace = true
                ColorPlaceholderTower(Color3.new(0,1,0))
            else
                canPlace = false
                ColorPlaceholderTower(Color3.new(1,0,0))
            end
            local x = result.Position.X
            local y = result.Position.Y + towerToSpawn.Humanoid.HipHeight + (towerToSpawn.PrimaryPart.Size.Y * 2)
            local z = result.Position.Z

            local cframe = CFrame.new(x,y,z) * CFrame.Angles(0, math.rad(rotation), 0)
            towerToSpawn:SetPrimaryPartCFrame(cframe)
        end
    end
end)

我尝试使用chatgpt,但它只能帮助停止错误,因为塔模型甚至没有出现。

roblox-studio
1个回答
0
投票

尝试使用 CFrame 代替

CFrame 文档

© www.soinside.com 2019 - 2024. All rights reserved.