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

I get this error message whenever i try to test my game! How do i fix it?

I get this error message: Workspace.Sounds.English.stayinthere**.Script:3: attempt to index nil with 'PlayerGui'**

My code:

local player = game:GetService("Players").LocalPlayer

player.PlayerGui.DDIALOUGE.TextLabel.Text = "GUARD: Stay in there!"
script.Parent.Playing = true
wait(1.751)
script.Parent.Parent.protip1.Script.Disabled = false
script:Destroy()

2 comments

0

Please answer!!

1

Is this a serverscript or is this a localscript?

1 answer

The problem is that

local player = game:GetService("Players").LocalPlayer

returned nil.

This is only the case if your script is ran from the server. Which doesnt have .LocalPlayer

Try to use cross-server communication to retrieve the player, or other methods such as getting their player through

game:GetService("Players"):GetPlayerFromCharacter()
--works on the server

hope this helped.

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