PlayerGui index'ed as nil

I am trying to make a script that will open a menu when it is clicked however when I press the button this error pops up
confusing
It says I am attempting to index PlayerGui as nil.
Here’s the script.
Line 6 is where the error appears

local Shop = game.ReplicatedStorage.ScreenGui
local ShopButton = script.Parent

ShopButton.MouseButton1Click:Connect(function(Clicked)
	local ShopClone = game.ReplicatedStorage.ScreenGui
	ShopClone.Parent = game.Players.LocalPlayer.PlayerGui
	if false then
		return
	end
end)

Is the type of script a LocalScript of a server script?

The script is a server script does it have to be a local script?

Yeah, try it in a LocalScript. The issue is, game.Players.LocalPlayer does not work in a server script, as it is referring to the local player, which is only on the client’s side.

Ohhhhhhh it works now thank you

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.