Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 9 years ago
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

Log in to vote
0
Answered by
Discern 1007 Moderation Voter
9 years ago

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!

0
Thanks, It helped alot. You also gave me a nice explanation. 10/10 kingstephen23 35 — 9y
Ad

Answer this question