Index Nil Error

Hey devforum! I’m running into an issue where my output is producing an ‘attempt to index nil with ‘playergui’’ error. No idea why this is happening because everything is referenced correctly.

Below is a snippet of my code where the error is being produced

local statusString = plr.PlayerGui:WaitForChild("status").statusString

This is the error in my output


Here is my ancestory tree
Screen Shot 2022-08-17 at 11.14.39 PM

If you could help me out that would be great!

Try this code:

local Players = game:GetService("Players")
local LPlayer = Players.LocalPlayer
local PlayerGUI = LPlayer:WatiForChild("PlayerGui")
local Status = PlayerGUI:WaitForChild("status")
local statusString = Status:WaitForChild("statusString")

You cannot access the LocalPlayer from the server

1 Like

This script is located inside of a part that will update the string everytime you touch it
I am getting the player from the function

I think i know how to fix this. This will take me a while to post so hang on…

Btw, is the statusString a string or bool value?

it is a string value

Ok… so what does the value say whenever the player touches it?

To verify just quickly here, you’re 100% certain that your plr variable is actually a player object right? I only ask this because, as I’m sure you’re aware, the Touched event gets the object that touched it rather than the player who touched it. It might be useful to do something along the lines of print(plr.Name) right before your line of error to ensure this is actually the player.

The value never changes because the part of the script that references it is what is causing the issue

Yes, I have a GUI that enables before the error and that is working just fine

Could you invite me to the game so that I can easily understand what is going on?

uh I could just send you a bit more of the script because I have some other scripts in there that i spent a couple hours on and i don’t really want anyone else to access them if that’s ok

Great… that would be more than enough.

great, hold on one second

local ready = true
local gui = script.Parent.timer


script.Parent.Touched:Connect(function(hit)
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
	local statusString = plr.PlayerGui:WaitForChild("status").statusString
	local status = plr.PlayerGui.status.gui.status
	statusString:GetPropertyChangedSignal("Value"):Connect(function()
		if ready == true then
			if statusString.Value == "Disguised" then
				statusString.Value = "Disguised"
				print("Disguised")
			else
                ready = false

your plr is nil

add a check
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr then
local statuString= plr.PlayerGui:Wait… etc…

May I ask what you’re using this variable for?

local gui = script.Parent.timer

Even after trying your solution it’s still coming back nil

local ready = true
local gui = script.Parent.timer


script.Parent.Touched:Connect(function(hit)
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
	local statusString = plr.PlayerGui:WaitForChild("status").statusString
	local status = plr.PlayerGui.status.gui.status
	statusString:GetPropertyChangedSignal("Value"):Connect(function()
		if plr then
			if ready == true then
				if statusString.Value == "Disguised" then
					statusString.Value = "Disguised"
					print("Disguised")
				else

It’s a reference to a timer used later on in the script