While true loop isn't doing if statement unless I rejoin

Issue I am having is if vs is greater than Timebroken it should print(“false”)
but it doesn’t.
I checked if the loop works by adding print(thing) and it prints true. No errors either, but if I rejoin and vs is greater than Timebroken then it would print false. This is a script in serverscriptservice.

local thing = false
local vs = workspace.Values.Value
thing = true
	while thing == true do
		task.wait()
		print(thing)
if workspace.Value:GetAttribute("TimeBroken") <= vs  then
print("false")
thing = false

Uh so what are you expecting with this code? Can you explain in more detail

local thing = true
local vs = workspace.Values
while thing do
	task.wait(0.1)
	print(thing)
       if workspace.Value:GetAttribute("TimeBroken") <= vs.Value  then
            print("false")
           thing = false
       end
end

Idk i reworded it because I wasnt sure what your code was trying to do, so I would assume this is correct.

You would have to have another part of the script set the vs value to be less then timebroken in order for “thing” to be set to false

if you wanted it to be the other way around, this statement would be correct then

workspace.Value:GetAttribute("TimeBroken") > vs.Value

If timebroken is greater then vs value

To print false if vs is greater than TimeBroken. The issue I am having is that when vs is greater than timebroken it does not print false unless if I leave and rejoin then it will.

how often is the timebroken attribute updated?
if you want the loop to continuously runinstead of only running once thing is set to false, then you can have a empty condition. for example:

while true do
	task.wait(0.1)
	print(thing)
       if workspace.Value:GetAttribute("TimeBroken") <= vs.Value  then
            print("false")
           thing = false
       end
end

I want the loop to stop running after it prints false. The attribute gets updated every 1 minute.

then the code i provided earlier should work?
what are the initial values of timebroken and vs and when is the code run at any given moment of time?

if the values are by default that vs is greater then timebroken then it will always only run once when the game starts.

Put the local variables in the while loop so they get updated. I think this should work.

1 Like

Is there another script in your game that modifies this value? If so, this would be the culprit because this is a static value that is only referenced once in your script.

1 Like

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