Instance exists but script cannot find it

캡처

local main = script.Parent.Main.UI
main.stamina.number.Text = tostring(math.floor(humanoid.status.block.stamina.Value * 100) / 100) .. "/100"

" stamina is not a valid member of ImageButton “UI” "
and when I do

for _, bruh in pairs(main:GetChildren()) do
    print(bruh:GetFullName())
end

Players.Eattato_HACKED2.PlayerGui.gui.Main.UI.stamina

wth how
why is this happening and how to fix this?

ah also healthbar got same problem but I just did local healthBar = main.health
and used healthBar and it fixed but this one is not fixing same way

1 Like

It’s low-likely to happen, but you should check if your ImageLabel “stamina” includes any whitespace such as spaces in its name, just in case

Perhaps it’s still loading when it’s referenced in the script. You could use :WaitForChild() to yield until it’s loaded.

I tried and it yields infinetely and stamina just appears in explorer in test…

Going off of what WilliamAlezandro said, is there a space or anything after “stamina”?

The LUA interpreter utilized by Roblox is flawed when it comes to instancing.

The interpreter probably thinks you’re referring to stamina as if it is a property of UI.

Instead, I recommend writing your code like this:

local GUI = script.Parent
local main = GUI.Main

local ui = main["UI"]
local border = ui["border"]
local health = ui["health"]
local stamina = ui["stamina"]

stamina.Text = tostring(math.floor(humanoid.status.block.stamina.Value * 100) / 100) .. "/100"
1 Like