UI Registering as 'nil' despite having "Archived" enabled

Guten tag!
I am trying to create a script that creates hallucinations after a certain value gets below 65

However, one of the values i have made gets stuck in an “Infinite Yield” or put it simply… it doesn’t “exist” and it halts the entire script from running

I have tried to look in the client as im playing if the nil value (Stats), exists, which it indeed does and even appears on my screen normally, i have also checked if Archived is true, which it is.

Here is the part of the script that defines these values the problem is the Status Value

--//Values//--
Players = game:GetService("Players")
Tween = game:GetService("TweenService")

local LP = Players.LocalPlayer
local Char = LP.Character or LP.CharacterAdded:Wait()
local PlayerUI = LP:WaitForChild("PlayerGui")

local energyBar = PlayerUI:WaitForChild("gameUI")
local Status = energyBar:WaitForChild("Stats")
local TLabel = Status:WaitForChild("TextLabel")
local ILabel = TLabel:WaitForChild("ImageLabel")
local Hum = Char:WaitForChild("Humanoid")

Red = Color3.fromRGB(85, 0, 0)
DefaultColor = Color3.fromRGB(0, 85, 0)

Percentage = "100"
Camera = workspace.CurrentCamera
maxSongs = 6

Here is where its located
image

So this line is causing the error?

Yes, it produces an infinite yield

Do you know if the energyBar variable or the stats UI are causing the error?

Can you show a screenshot of the complete errror?

I have checked those and i haven’t found anything
Here is the error i get, which proves none of the other values are wrong as it looks in the correct place where it should be located
image

Could you check if the frame exists at runtime? It would be under player.PlayerGui. Also could you check that the ScreenGui’s ResetOnSpawn property is false?

Replace that line with this line and see if this just to test if the rest of the script would run:

local Status
repeat
   Status = energyBar:FindFirstChild("Stats")
   wait()
until Status
print(Status)

Maybe see if anything prints?

Nothing has printed and the script seems to still be broken

The value im looking for is parented to the right places on spawn…
image

Is the ResetOnSpawn property false on gameUI? I’ve run into a similar issue and it was because I was referencing an old instance that was garbage collected already

ResetOnSpawn is true but perhaps something else is here that im not catching
image

Gotcha. Try setting it to false.

1 Like

For what ever reason that has fixed my problem, thank you for your help

That’s because when the player spawns, the screen gui is reset which means anything that wasn’t there before (like objects added by scripts) would be removed when the player respawns.

So basically

I have a ScreenGui
Add a button called “TextButton” via script
Reset
TextButton no longer exists.