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

Why am I getting a nil value for the PlayerGui folder?

Server script:

function onMouseClick()
	local player = game.Players.LocalPlayer
	player.PlayerGui.celMenu.Enabled = true
end

script.Parent.MouseClick:Connect(onMouseClick)	

Error:

Workspace.Part.ClickDetector.Script:3: attempt to index nil with 'PlayerGui'

I want this GUI to be enabled when a player clicks a part but I get the error above whenever I click the part.

1 answer

✓ Accepted answer

There is no LocalPlayer in a ServerScript. Instead you can get the player from the player parameter.

function onMouseClick(player) 
    player.PlayerGui.celMenu.Enabled = true
end

script.Parent.MouseClick:Connect(onMouseClick)  

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