This might be a bit hard to understand, but (the following is not what I’m using this for but it’s easiest to understand like this) say you walked into an area, and after 3 seconds you got teleported. If you did something like
player.EnteredArea:Connect(function()
wait(3)
if player.IsIn(area) then
player:Teleport()
end
end)
(Obviously this wouldn’t work but it’s just an example) If the player left and went in again in between those 3 seconds, they would still be teleported. Does anyone know how I could do something to fix this?
1 Like
Well for the example since you check after the wait then it would not teleport if your not in the zone so that way works.
Yeah but if the developer was looking for the player to be teleported specifically after 3 seconds then it would just seem immediate to the player. That example wasn’t that great but do you get the general idea of what I’m trying to achieve?
I know you could do something like
for count = 0.1, 3, 0.1 do
wait(0.1)
if not player.IsIn(area) then
break
end
end
but I would prefer if there was a shorter solution because that takes up six lines.
You could do (I think, don’t know if it works like that in a repeat until)
local count
repeat task.wait(0.1)
count += 0.1
until not player.IsIn(Zone) or count == 3
I have a different example, say the player clicked a button and started a stopwatch, if they stopped the stopwatch but then started it again in under 1 second, then it would keep going from where it left off. Or have two going at the same time making it look buggy.
E.g.
local minutes,seconds = "0","0"
repeat
seconds = tostring(tonumber(seconds+1))
if seconds == "60" then
minutes = tostring(tonumber(minutes+1))
seconds = "0"
end
counter.Text = string.format("%02d:%02d",minutes,seconds)
until waiting == false
If I were to do this then I would have to add task.spawn or something which means I’d have two loops running at the same time.