#Simple loops

25 messages · Page 1 of 1 (latest)

lime tangle
#

Not sure if this may work but try this:

#

wait

#

what script is this

#

if it's a client script it should stop

clever shuttle
#

If it's hard to understand, i have a function and all i wanna do is without affecting the function i want the function to end if there is not enough players ( i know how to detect the players etc ) but not how to end the function etc.

graceful oliveBOT
#

studio** You are now Level 5! **studio

lime tangle
#
local AmountOfPlayers
local Time = 150
game.Players.PlayerAdded:Connect(function(Plr)
AmountOfPlayers += 1
end)
game.Players.PlayerRemoving:Connect(function(Plr)
AmountOfPlayers -= 1
end)

while wait(1) do
Time -= 1
if AmountOfPlayers < (Minimum Players) then
break
end
end
clever shuttle
#

Thjis is not what i want.

in the example here:

local function ExampleFunction()
task.wait(150)
end

In this function you can see a 150 timer, it's say it's half way through but a player leaves.

I dont want it to wait for it to end, i want to end the function intantly. without waiting

tacit quarry
#

playerLeft= false
counter =0
game.Players.PlayerRemoved:Connect(function(player)
playerLeft= true
end)
function after()
print("after")
end
while task.wait(1) do
if playerLeft then
playerLeft= false
counter = 0
break
end
counter += 1
if counter == 150 then
after()
end

clever shuttle
#

That's for this example, but i have a function without that "wait(150)" seconds just a long function with stuff, waits, etc..
Which means counters will not work.

tacit quarry
#

I dont think u can

clever shuttle
#

There's a game named "courtroom" that has waits and etc..

And when the player requirement is not met it completely cuts off everything and ends the function Idk how they do it

tacit quarry
#

u can add a
if playerLeft then
return
end
at each line but it s ugly

clever shuttle
#

Yeah not what i'm looking to do

#

I need an alternative

lime tangle
#

ends

#

every 1 second it checks

#

if minimum is exceeded

#

then it breaks the timer

clever shuttle
#

Yes but as stated before, my code is not a timer, i used the timer as an example

lime tangle
#

how do you call the function

#

by ()?

clever shuttle
#

For now yes