My Text Isn't working

Hello! I am currently making a game and an error occured. I was done with my stats but when I did this, it did’nt show. And there was no errors in the output. Also in my stats, when I changed the value, I checked in players, “PlayerStats” then “Wood” (Currency) and my value didn’t change. :hushed:

local text = script.Parent
local plr = game.Players.LocalPlayer

while true do
wait() – This prevents it from causing a script error or shutdown. DON’T DELETE IT.
text.Text = plr:WaitForChild(“PlayerStats”).Wood.Value
end

while true do
wait(4)
plr.PlayerStats.Wood.Value = 12
end

2 Likes

Are you setting the Wood Value on the server or client?
What happens if you just print out the value? Does it print anything?

I am setting the world value on a server script (local script) and no, it doesn’t print any errors.

I checked many times. I printed, I looked at my stats, ect.

I mean does it print anything, and what do you mean “on a server script (local script)”?

No, it doesn’t print anything and I mean I am changing my player’s stats on a local script.

you cannot do that, you have to use a remote event to actually change it

Wait, I tried this before, and it worked. But I will give it a shot. (I am using it on a local script btw)

Firstly Your second while loop will not run because While loops “pause” or yield the script until it’s finished

Jay, I edited my Wood stats in studio and it repeated on the gui.

I was just going to ask if it was all in the same script.

Yes, it is. It is all in on e script (except leaderstats)

Adding on to @Jaycbee05 point:

     local text = script.Parent
     local plr = game.Players.LocalPlayer

     while true do
     wait() --This prevents it from causing a script error or shutdown. DON’T DELETE IT.
     text.Text = plr:WaitForChild(“PlayerStats”).Wood.Value
     end

     while true do -- this will never run
     wait(4)
     plr.PlayerStats.Wood.Value = 12
     end

Oh! I get it. Let me try and see…

Carbyne you mean the script text?

just put ` at the start and the end of the script or select the script and press the button to the left of the upload icon

Ok. I will do that. I am gonna try it

:o the script works! Thanks! It was because I did while true do like 2 times.

This is what you should do:

 local text = script.Parent
 local plr = game.Players.LocalPlayer

 plr:WaitForChild(“PlayerStats”).Wood.Changed:Connect(function(Wood)
     text.Text = Wood.Value
 end

 plr.PlayerStats.Wood.Value = 12

As others have said, using a while loop will just cause the script to yield until that loop finishes. For setting the text to what the number is, instead do this:

plr.PlayerStats.Wood:GetPropertyChangedSignal('Value'):Connect(function()
    text.Text = tostring(plr.PlayerStats.Wood.Value)
end)

However, note how I used the tostring function? You can’t set a string value as a number value. Using tostring will convert the number value into a string, which lets the Text value be changed.

I like that way, it is a more “Advanced” method. I will use that.