2013-06-19 91 views

回答

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) 
    tool:Clone().Parent = player:FindFirstChild("Backpack") 
end)