我想为ROBLOX创建一个脚本,该脚本会将一个工具放在点击某个部件的玩家的背包中。这是一款名为 Undead Nation 的游戏。
答案 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)