How to make a script where the player who clicked on the tool will make the tool to go to his backpack?
function OnClick(Clicker)
print("The player who clicked is named: " .. Clicker.Name)
script.Parent:Clone().Parent = game.Players.LocalPlayer.BackPack
script.Parent:Destroy()
end script.Parent.ClickDetector.MouseClick:connect(OnClick)
Add a ClickDetector into the handle of the tool along with this script.
1 | script.Parent.Parent.ClickDetector.MouseClick:connect( function () |
2 | for _, v in pairs (game.Players:GetPlayers()) do |
3 | print ( "The player who clicked is named: " .. v.Name) |
4 | script.Parent.Parent:Clone().Parent = v.Backpack |
5 | script.Parent.Parent:Destroy() |
6 | end |
7 | end ) |