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