关于 'attempt to index nil with 'GetMouse'' 的放置代码问题,我在一个需要变量代码后没有获得任何的变量代码

我已经尝试了我的其他问题的答案,但它没有起作用。我对Lua相当新,也许我错过了什么。

local player = game.Players.LocalPlayer
local Mouse = player.GetMouse()
local Block = game.ServerStorage.Experimental

Mouse.Button1Down(place)

function place()
    Mouse.Hit.X = PosX
    Mouse.Hit.Y = PosY
    Mouse.Hit.Z = PosZ

    PlacedBlock = Block:Clone()
    PlacedBlock.Parent = game.Workspace
    PlacedBlock.Position = Vector3.new(PosX,PosY,PosZ)
end
点赞
用户13072308
用户13072308

简单的错误在于您在调用 GetMouse() 时使用了 . 而不是 :。 一旦更正,您的代码就应该可以正常工作 :D

2020-05-06 17:50:45
用户13461896
用户13461896

这应该行!

local player = game.Players.LocalPlayer
local Mouse = player:GetMouse()
local Block = game.ServerStorage.Experimental

function place()
    PlacedBlock = Block:Clone()
    PlacedBlock.Parent = workspace
    PlacedBlock.Position = Mouse.Hit.p
end

Mouse.MouseButton1Click:Connect(place)
2020-05-06 20:07:11