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
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