0

# How do I fix attempt to index nil with 'PlayerGui'?

I've been trying to code some dialogue, it works perfectly so I decided to add options to it. But for some reason I keep getting this error that I don't usually encounter in coding. I'm sorta just a beginner so can anyone help me?

--Error message was:
Players.Dragonboy99711.PlayerGui.MainGui.DialogueFrame.OptionsFrame.Option1.Script:7: attempt to index nil with 'PlayerGui'  -  Server - Script:7

--Here's the code:
local createDialogueEvent = game.ReplicatedStorage.Remotes.createDialogueEvent
local hideDialogueEvent = game.ReplicatedStorage.Remotes.hideDialogueEvent
local setDialogueImageEvent = game.ReplicatedStorage.Remotes.setDialogueImageEvent
local SetoptionsEvent = game.ReplicatedStorage.Remotes.optionsEvent

local player = game.Players.LocalPlayer
local dialogueFrame = player.PlayerGui.MainGui.DialogueFrame
local optionsFrame = player.PlayerGui.MainGui.DialogueFrame.OptionsFrame

script.Parent.MouseButton1Click:Connect(function()
if optionsFrame.Option3.Text == "I would like a 2 number 9s, number 6 with extra dips,..." then
SetoptionsEvent:FireAllClients("","","","")
createDialogueEvent:FireAllClients("no")
wait(1.5)
createDialogueEvent:FireAllClients("ok go away if your not here for what ur meant to do")
wait(3)
hideDialogueEvent:FireAllClients()
wait(0.9)
wait(1)
end
end)

--Ignore the dialogue lol i was just writing this for a friend!

0
LocalPlayer can only be called from a LocalScript (a client). Based on your error message, you are calling it from the server. appxritixn 2235 — 1y