Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Inserting Tool into BackPack via ClickDetector?

Asked by 6 years ago

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)

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

Add a ClickDetector into the handle of the tool along with this script.

script.Parent.Parent.ClickDetector.MouseClick:connect(function()
    for _, v in pairs(game.Players:GetPlayers()) do
    print("The player who clicked is named: " .. v.Name)
    script.Parent.Parent:Clone().Parent = v.Backpack
    script.Parent.Parent:Destroy()
    end
end)
Ad

Answer this question