【问题标题】:A placement code is saying that 'attempt to index nil with 'GetMouse'' and I have not got any variable codes after a code that needs it一个放置代码是说“尝试用'GetMouse'索引nil”并且在需要它的代码之后我没有得到任何可变代码
【发布时间】:2020-08-21 15:12:01
【问题描述】:

我已经尝试过回答我的其他问题之一,但没有奏效。我对 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

【问题讨论】:

    标签: lua roblox


    【解决方案1】:

    这里的简单错误是您在调用GetMouse() 时使用了. 而不是:。一旦你替换了你的代码应该可以正常工作:D

    【讨论】:

      【解决方案2】:
      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)
      

      这应该可行!

      【讨论】:

      • 不幸的是,出现了同样的错误信息。你知道这是为什么吗?可能是因为放错地方了。 game.StarterPack
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-08-11
      • 2013-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多