我如何制作这个roblox脚本(playerwhoclicked)?

时间:2013-06-19 14:13:36

标签: lua roblox

我想为ROBLOX创建一个脚本,该脚本会将一个工具放在点击某个部件的玩家的背包中。这是一款名为 Undead Nation 的游戏。

1 个答案:

答案 0 :(得分:4)

ROBLOX有一个ClickDetector对象,允许脚本通过ClickDetector.MouseClick事件检测部件的点击次数。传递给该事件的侦听器的一个参数是单击的玩家的对象,因此侦听器可以将工具放入该玩家对象的背包对象中。

下面的代码,其中tool暗示是一个引用你想放在玩家背包中的工具对象的变量(它将被克隆),如果你把它放在应该在点击播放器时为播放器提供工具的部分:

-- Create a click detector in the part in order to be able to detect clicks.
local click_detector = Instance.new('ClickDetector', script.Parent)

-- Give the tool to the player when the button is clicked
click_detector.MouseClick:connect(function(player)
  local newTool = tool:Clone()
  newTool.Parent = player:FindFirstChild("Backpack")
end)
相关问题