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

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

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

✓ Accepted answer

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)

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