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

Why does my giver script only work in Test Mode? Please correct me.

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)

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!

1 comment

0

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

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