01 | Timberwolf = game.Workspace.Timberwolf |
02 |
03 | Timberwolf 2 = game.Lighting.Timberwolf |
04 |
05 | function onClicked(hit) |
06 | Timberwolf:remove() |
07 | wait( 1 ) |
08 | Timberwolf 2 :Clone().Parent = |
09 | game.Players.LocalPlayer.Backpack -- Thispart works fine in Test mode, but in game it fails. |
10 | end |
11 |
12 | 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.
01 | Timberwolf = game.Workspace.Timberwolf |
02 |
03 | Timberwolf 2 = game.Lighting.Timberwolf |
04 |
05 | function onClicked(playerWhoClicked) |
06 | Timberwolf:Destroy() --Use Destroy, it is MUCH more efficient. |
07 | wait( 1 ) |
08 | Timberwolf 2 :Clone().Parent = playerWhoClicked.Backpack --Parent the tool from playerWhoClicked, which is the character who clicked the ClickDetector which is on line 5. |
09 | end |
10 |
11 | script.Parent.ClickDetector.MouseClick:connect(onClicked) |
If I helped you, be sure to accept my answer!