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)
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!