Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago
Edited by imKirda 3 years ago

Please encode Lua code in the Lua block code tag (look for the Lua icon in the editor).

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

0
also for some reason its not showing the code in multiple lines so here is an image of it: https://gyazo.com/203396bdb9919db78e59d3ef917ca189 XxSpiritDuoxX 2 — 3y
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 BlackFateX 19 — 3y
0
"then" used for if statement: if-then RektwayYTB 123 — 3y

1 answer

Log in to vote
0
Answered by
imKirda 4491 Moderation Voter Community Moderator
3 years ago
Edited 3 years ago

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
Ad

Answer this question