Timberwolf = game.Workspace.Timberwolf
Timberwolf2 = game.Lighting.Timberwolf
function onClicked(hit)
Timberwolf:remove()
wait(1)
Timberwolf2:Clone().Parent =
game.Players.LocalPlayer.Backpack -- Thispart works fine in Test mode, but in game it fails.
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)
✓ ANSWER ACCEPTED
Why does my giver script only work in Test Mode? Please correct me.
1 answer
✓ Accepted answer
game.Players.LocalPlayer only works if the script is inside a LocalScript. However, MouseClick will only fire if it is in Workspace inside a part, so you cannot use both in a script.
MouseClick has a parameter which returns the player who clicked the given ClickDetector, so just parent the cloned tool/hopperbin into the player from there.
Timberwolf = game.Workspace.Timberwolf
Timberwolf2 = game.Lighting.Timberwolf
function onClicked(playerWhoClicked)
Timberwolf:Destroy() --Use Destroy, it is MUCH more efficient.
wait(1)
Timberwolf2:Clone().Parent = playerWhoClicked.Backpack --Parent the tool from playerWhoClicked, which is the character who clicked the ClickDetector which is on line 5.
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)
If I helped you, be sure to accept my answer!
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Thanks, It helped alot. You also gave me a nice explanation. 10/10