I need help with attempting to index nil with ':WaitForChild()'

What is the issue?
So basically, I’m trying to show a GUI when the player has triggered a proximity prompt. It didn’t work with trying remote events so I went more basic and tried to activate the GUI with the server script. The code is this:

local person = game.Players.LocalPlayer
local gui = person:WaitForChild("PlayerGui")
local frame = gui:WaitForChild("MainFrame")

script.Parent.ProximityPrompt.Triggered:Connect(function()
	frame.Visible = true
end)

The error is it’s saying "attempting to index nil with ‘:WaitForChild()’, this is the output:
image

When I remove ‘WaitForChild()’ And I just address it verbally as person.PlayerGui, it says this:
image

Any help as this is very confusing…?

You’re trying to define the LocalPlayer from a Server Script, which will be unable to be found because there’s no way of telling what exact “Player” you’re looking for on the server

Since you’re actually using a ProximityPrompt instead, you can reference the parameter it gives you (Which is the Player by default)

local Part = script.Parent

Part.ProximityPrompt.Triggered:Connect(function(Plr)
    local PlrGui = Plr:WaitForChild("PlayerGui")
    local Frame = PlrGui:WaitForChild("MainFrame")

    Frame.Visible = true
end)
3 Likes