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

My Script won't change the parents of another script?

Asked by
neoG457 315 Moderation Voter
9 years ago
function onClicked(playerWhoClicked)
 local eat = game.ReplicatedStorage.EatOptions:Clone()

local pg = game.Players.LocalPlayer.PlayerGui

eat.Parent = pg

end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

I'm trying to move a local script from Replicated Storage when I click the brick, however I cant use LocalPlayer with it because this is a server script and I'm not sure what to do from this point onwards. Please Help.

1 answer

Log in to vote
1
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

Your problem is that you're trying to get the player instance through game.Players.LocalPlayer, which will not work through a server-script.

So to fix? The MouseClick event actually returns the player that clicked. So there's no need to define the player other than a Parameter(;

NOTE: if FilterIngEnabled is on, then ClickDetectors will not work.

local eat = game.ReplicatedStorage.EatOptions:Clone()

--'plr' is the player
script.Parent.ClickDetector.MouseClick:connect(function(plr)
    local pg = plr.PlayerGui
    eat.Parent = pg
end)
Ad

Answer this question