I was wondering if it’s possible to stuff a “Break” into a “for i =”
and if so, How i would fit it in here
DeathClock = 0
Ran = math.random(20, 30) -- Random time system
print(Ran)
for hypo = 1, Ran do
script.Parent.BackgroundTransparency -= 0.9 / Ran -- Death Clock Calculation
DeathClock += 1
print(DeathClock)
wait(1)
end
if DeathClock == Ran then -- "Death" System
game.Players.LocalPlayer:Kick("You Suffered from Hypothermia.")
end
i’m trying to make it so when you teleport somewhere in the game, or perhaps when you touch something the death clock stops and resets for the player who teleported.
DeathClock = 0
Ran = math.random(20, 30) -- Random time system
print(Ran)
for hypo = 1, Ran do
script.Parent.BackgroundTransparency -= 0.9 / Ran -- Death Clock Calculation
DeathClock += 1
print(DeathClock)
task.wait(1)
if DeathClock == Ran then
-- add whatever code here
break -- ends the loop
end
end
-- for i loop here
from what you want i took out the player kick function. you could add it back in the if statement if you want
DeathClock = 0
Ran = math.random(20, 30) -- Random time system
print(Ran)
for hypo = 1, Ran do
script.Parent.BackgroundTransparency -= 0.9 / Ran -- Death Clock Calculation
DeathClock = hypo - 1 -- Try this (-1 because deathclock starts at 0 but hypo start at 1)
print(DeathClock)
wait(1)
-- Hypo is is incremented by one every time this loop and hypo will always equal Ran at the end
end
if DeathClock == Ran then -- "Death" System
game.Players.LocalPlayer:Kick("You Suffered from Hypothermia.")
end
This might work since the loop exits once its done
But if your looking to run a for loop one time try
for i =1,1 do
--Your code
end
You can’t necessarily ‘break’ a for loop since it’ll run how many times needed until i is satisfied I think. Hope this helped even a little bit
Nevermind I didn’t read the last part of your question where you want to basically exit the loop on a function or something else here I used a bool value, so
local reset = false -- You can change the value of reset using a function or use a BoolValue Instance
DeathClock = 0
Ran = math.random(20, 30) -- Random time system
print(Ran)
for hypo = 1, Ran do
script.Parent.BackgroundTransparency -= 0.9 / Ran -- Death Clock Calculation
DeathClock += 1
print(DeathClock)
wait(1)
if reset == false then
continue
else
break
end
end
if DeathClock == Ran then -- "Death" System
game.Players.LocalPlayer:Kick("You Suffered from Hypothermia.")
end
An if statement could help let me know if if it did or didn’t