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

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

Asked by 2 years ago

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()
0
Please answer!! vobidobo 2 — 2y
1
Is this a serverscript or is this a localscript? NotThatFamouss 605 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago

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.

Ad

Answer this question