The UI Text didn't change after I change the value

  1. What do you want to achieve?
    UI text changing when value changed

  2. What is the issue? Include screenshots / videos if possible!


    you will see the value is changed while the text didn’t change

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    using loop(while true do) says error like “exhausted allowed execution time”

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

-- very simple right?
local TempRecord = workspace:WaitForChild("Temperature")
-- while true do
if script.Parent.Parent.Parent then
script.Parent.Text = "Temp : "..TempRecord.Value.." °C"
	end
--	end

Well,

  • You Commented out the while loop

  • You Aren’t yielding per iteration causing the loop to crash the game and break

  • no other code appears to be running

Therefore the text will only update once, as you aren’t telling it to update, if that if statement is supposed to indicate something, it will only run once, so use a .Changed Event for this instead of a while loop as it is generally more efficient and takes less resources to accomplish.
Another Method for formatting text can be with string.format()

format = string.format
script.Parent.Text = format("Temp : %d °C", newValue) -- updates First outside

TempRecord.Changed:Connect(function(newValue) -- Updates when there is a Change
script.Parent.Text = format("Temp : %d °C", newValue) -- basically formats the string
end)

The issue is that the text is only setting once. Nothing is telling the script to continue reading that temperature value. If you uncommented the while loop, the game will crash because there’s no yield in the loop. What @DasKairo suggested is the most efficient and practical, I would go with that.

Basically what I said:


hmmmmmmmmmmmmmmmmmmm :thinking:

Are you using LocalScript or normal Script?

It’s server script and it’s under the textlabel

Have you read the first reply yet? It is the solution.

but yes thanks to @DasKairo, now it’s changing and work
robloxapp-20230213-2259171.wmv (388.2 KB)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.