While true do not working!

Hello!

I’m working on a reactor core game as usual.

I tried implementing an integrity system but the problem is the while true do somehow doesn’t work.

Evidence: dude why do you need evidence

while true do
	if script.Parent.Parent.Value > 4500 then
		script.Parent.Value -= 0.1
	end
	wait(0.25)
end

plz im running out of time

1 Like

I think you meant script.Parent.Parent.Value -= 0.1?

1 Like

Oops! Forgot to mention. IntegrityScript is parented in the Integrity NumberValue. script.Parent.Parent refers to Temperature NumberValue.

if doesnt working use “print” its helpful

It’s printing literally nothing. Weird.

i dont know why dont working, but i have one more way;

game:GetService("RunService").HeartBeat:Connect(function()
     -- server loop
end)
-- or
game:GetService("RunService").RenderStepped:Connect(function()
     -- client loop
end)

Nope. Doesn’t work. D:
What can I do?
I think I’ll just wait for someone else.

I think you should write

script.Parent.Value = script.Parent.Value - 0.1

what’s -= for?

-= Is a shortened version of number = number - 1

3 Likes

thank you and sorry for stupid reply

3 Likes

value += 1
value = value + 1

this ^

3 Likes

I put the wait(0.25) inside of the if statement and it just worked I don’t how tho

What type of script is this and where is the location?

its Heartbeat, not HeartBeat :smiley:

local InnerValue = script:FindFirstAncestorWhichIsA("ValueBase")
local OuterValue = InnerValue:FindFirstAncestorWhichIsA("ValueBase")

while true do
	task.wait(0.25)
	if OuterValue.Value > 4500 then
		InnerValue.Value -= 0.1
	end
end

If this doesn’t work then you’ve setup something incorrectly on your end, perhaps share a screenshot of your instance hierarchy so that we can get a better understanding of how everything is organised.

What service is the value located in? If it is somewhere like ReplicatedStorage, the script won’t run.

what If you tried using repeat until instead?

Are you sure the script parent value even has a near value altogether?

To me, it sounds like the game automatically nullified the while true do as a defense mechanism. There’s this defense mechanism that the game has where if you type

repeat
print("permatrago")
--wait() I'm too cool to be waiting B)
until nil

the game instead of crashing now breaks the loop when it has a overload.

And because this is adding a value up every 25 miliseconds, I assume it did the same.

Does it need to be 0.1? at 0.25 seconds?

The script is located in the Integrity NumberValue. The NumberValue is in the Temperature NumberValue.

The NumberValue is located in a Values folder and the folder is in ReplicatedStorage

Try doing this:

while wait(0.25) do
      if script.Parent.Parent.Value > 4500 then
      script.Parent.Value -= 0.1
   end
end

METHOD1:
while script.Parent.Parent.Value > 4500 do
script.Parent.Value -= 0.1
wait(0.25)
end

METHOD2:

while true do
if script.Parent.Parent.Value > 4500 then
script.Parent.Value -= 0.1
else
break
end
wait(0.25)
end

The problem: While true do/while wait() do literally means for the loop to run infinitely/until it breaks

Also, using while loops outside of very specific situations is a bad practice. In this case I believe it’s ok but I recommend you take a look at the task scheduler

https://developer.roblox.com/en-us/articles/task-scheduler