Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

I created some code but im confused why the "then" part of the while loop is not working?

the title says it all,im just confused why this isnt working

the "while time1 > 0 then" part is working but the first While is not working and im not sure why

TimeLimit is the script,Time is a IntValue,Enabled is a BoolValue

while script.Parent.TimeLimit.Enabled == true then
    time1 = script.Parent.TimeLimit.Time
    while time1 > 0 then
        wait(1)
        time1 = time1 - 1
    end
    script.Parent.Humanoid.Health = 0
end

the "then" of the first While loop has a red line below it meaning its not going to work and it does not have a collapse and expand that conditions and while loops normally have

3 comments

0

also for some reason its not showing the code in multiple lines so here is an image of it: https://gyazo.com/203396bdb9919db78e59d3ef917ca189

0

Is the time1 value a IntValue outside of the script? Because if yes, you just need to put to the end a .Value, like time1.Value < 0

0

"then" used for if statement: if-then

1 answer

This is not how Lua works, while loops use do instead of then, simply change

while script.Parent.TimeLimit.Enabled == true then

to

while script.Parent.TimeLimit.Enabled == true do

and

while time1 > 0 then

to

while time1 > 0 do

If statements are the ones who use then, for example

if (true) then
	...

here is a page for Lua documentation about loops.

That's not all tho, read about Values, they are Instances so your variable time1 refers to Instance, you need to get it's Value, for that you type time1.Value, that get's it's property called Value.

while time1.Value > 0 do

--

time1.Value -= 1 -- same as time1.Value = time1.Value - 1

So the whole script would look like this

while script.Parent.TimeLimit.Enabled == true do
	time1 = script.Parent.TimeLimit.Time
	while time1 > 0 do
		wait(1)
		time1.Value -= 1
	end
	script.Parent.Humanoid.Health = 0
end

This discussion is preserved as it was. New answers, comments, and votes are closed.