Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Cloning a tool when touched while the tool is given?

**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

✓ Accepted answer

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)

3 comments

0

Thanks. my scripting wasn't really good :/

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...

0

I'm not using the touched event actually :P

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."

This discussion is preserved as it was. New answers, comments, and votes are closed.