Why does the text not change?

For some reason the text is not changing even though it is parented to the correct object.
Output:
Infinite yield possible on ‘Players.SilentSuprion:WaitForChild(“LeaderStatsScript”)’ - Studio

Script:
local Player = game.Players.LocalPlayer

local Leaderstats = Player:WaitForChild(“LeaderStatsScript”)

local Exp = Leaderstats:WaitForChild(“Exp”)

while wait() do

script.Parent.Text = “Exp”…Exp.Value

end

You should have a script exactly named LeaderStatsScript inside the Player Object, if it can’t find it then it’ll result as an “infinite yield possible” warning cause it’s still searching for it

There is an object that is name that.

game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new(“Folder”,player)
leaderstats.Name = “leaderstats”

local Cash = Instance.new("IntValue",leaderstats)
Cash.Name = "Cash"

local Lvl = Instance.new("IntValue",leaderstats)
Lvl.Name = "Lvl"

local Exp = Instance.new("IntValue",leaderstats)
Exp.Name = "Exp"

end)

Nope lol

Your leaderstats variable is only named as leaderstats, and I don’t see a name in there called “LeaderStatsScript” anywhere inside the script

Try this:

game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "LeaderStatsScript"

local Cash = Instance.new("IntValue",leaderstats)
Cash.Name = "Cash"

local Lvl = Instance.new("IntValue",leaderstats)
Lvl.Name = "Lvl"

local Exp = Instance.new("IntValue",leaderstats)
Exp.Name = "Exp"
end)
local Player = game.Players.LocalPlayer

local Leaderstats = Player:WaitForChild("leaderstats")
local Exp = Leaderstats:WaitForChild("Exp")

while wait() do
script.Parent.Text = "Exp " .. Exp.Value
end

In order to work it needs to be named “leaderstats” and it still doesn’t work

Then you have to reference your Leaderstats variable as leaderstats, don’t try and change the name it, otherwise you’ll get that warning

local Player = game.Players.LocalPlayer
local Leaderstats = Player:WaitForChild("leaderstats")
local Exp = Leaderstats:WaitForChild("Exp")

Exp.Changed:Connect(function(NewValue)
    script.Parent.Text = "Exp "..NewValue
end)

Still does not work sadly. The value is 5 but the text is 0.

I think I forgot to convert it into a string

local Player = game.Players.LocalPlayer
local Leaderstats = Player:WaitForChild("leaderstats")
local Exp = Leaderstats:WaitForChild("Exp")

script.Parent.Text = "Exp "..tostring(Exp.Value)

Exp.Changed:Connect(function(NewValue)
    script.Parent.Text = "Exp "..tostring(NewValue)
end)

Try this?

1 Like

Pretty sure you will also need to change the text before the event starts.

This should work because on my cash leaderstats it works but not on the Exp gui.

Are you getting any errors? If you aren’t, can you add print statements to check what’s working and what’s not?

There is no error and it does not print anything when I do print.

local Player = game.Players.LocalPlayer
local Leaderstats = Player:WaitForChild("leaderstats")
local Exp = Leaderstats:WaitForChild("Exp")
print("Variables found")

script.Parent.Text = "Exp "..tostring(Exp.Value)
print("Changing things")

Exp.Changed:Connect(function(NewValue)
    script.Parent.Text = "Exp "..tostring(NewValue)
    print("Changing things")
end)

The only thing that I could see is that your organized your hierarchy the wrong way, but I don’t think that would be the issue

It prints but the text does not change.

You’re probably changing the wrong thing then? Can we see how the Gui is set up? That’s probably why it isn’t working

This is off topic but instead of using a loop to update the players xp, i’d use

" :GetPropertyChangedSignal(“Value”):Connect(function() "

this detects when the value is changed

Ok what

The only other thing I can think of is sending a place template here for us to debug & figure out, I have no clue why it’s not working on your side