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

Cloning a tool when touched while the tool is given?

Asked by 8 years ago

**Well, anyone can help me with cloning a tool when touched while the tool is given?

function onClicked()
    game.Workspace.EmptyCup:clone()
end

game.Workspace.EmptyCup.Touched:connect(onClicked)

2 answers

Log in to vote
0
Answered by 8 years ago

You have to make a variable for the clone and then set its parent as the players backpack in order to put it into the players inventory.

function onClicked(plr )
    local clone = game.Workspace.EmptyCup:clone()
    clone.Parent = plr.Backpack
end

game.Workspace.EmptyCup.Touched:connect(onClicked)

0
Thanks. my scripting wasn't really good :/ Syntax_404 37 — 8y
0
Your using the touched event a player can't be an argument of it however the object that is touching can be the argument of it therefore just saying plr.Backpack isn't going to work since the part that will touch it won't have a object under it called backpack... Also you are not even checking for the humanoid if you don't then the script will break... KingLoneCat 2642 — 8y
0
I'm not using the touched event actually :P User#11440 120 — 8y
Ad
Log in to vote
0
Answered by 8 years ago

So, this?

function onClicked(playerWhoClicked )
game.Workspace.Cups:FindFirstChild("Humanoid")
local clone = game.Workspace.Cups.EmptyCup:clone()
clone.Parent = playerWhoClicked.Backpack
print "Tool has been added into target's inventory."

Answer this question