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

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

Asked by 3 years ago

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

Log in to vote
1
Answered by 3 years ago

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

Answer this question