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

Stopping game when all players die/stop function when all players die? [SOLVED]

Asked by 5 years ago
Edited 5 years ago

Solution: So first of all, thanks to fredfishy for trying to help me out, but I didn't use their solution. I used another method and tried it and it worked. (basically used int values and did a loop of the time until the int values was changed, which was when all the players on the playing team died, which is kinda weird but it was easier for me to understand)

I'm making this one game where basically you survive until the round ends or when all the players die.

(also there's two teams: Playing and Out, I already made it that the players change teams when the game stops/starts)

I only scripted when the round ended, the game ends.

The part where I'm confused, however, is how to end the game when all players on the "Playing" team die and to stop the timer and game when that happens?

(the clocktimethingy is an int value that corresponds to the timer in the game)

local function startGame()
status.Value = "Intermission"
clocktimethingy.Value = 20
wait(20)
if clocktimethingy.Value ~= 0 then
    clocktimethingy.Value = 0
end
status.Value = "Game is starting!"
pickRoom() --don't worry about this function, just picks the room
wait(1)
status.Value = "Game currently in progess..."
teleportPlayers() --again, don't worry about this
wait(1)
clocktimethingy.Value = 45
wait(45)
if clocktimethingy.Value ~= 0 then
    clocktimethingy.Value = 0
end
unloadRoom() --unloads the room, basically clears a folder with the map in it, ultimately where the game ends
end


--below is how the game starts
while true do
    startGame()
end
0
Add all players to a table. Bind every player's character's humanoid's `.Died` event to a function that removes them from the table, and restarts the game if it's now empty. fredfishy 833 — 5y
0
thanks, but how should i stop the timer and the wait(45) on line 15 when I restart the game? meteorcrasher118 35 — 5y
0
Spawn a process which ends the game after 45 seconds by itself. Then clean it up if you end it from all players dying. fredfishy 833 — 5y
0
If you don't mind about a slightly more crude implementation: 1) put a random string value in each player's character when the round starts 2) when their character dies, the value will be removed 3) therefore, checking if a player has died means checking for that value 4) check every 5 seconds that the value is still there in at least one player 5) after 9 failed checks (5 * 9 = 45), restart the g fredfishy 833 — 5y
0
so I just searched some things up and tried making something off of it, but I'm still left very confused, how do you clean up the process? (and also by "spawn a process", do you mean use spawn()/coroutine? I don't really get this as much because I've never really touched this stuff before and I'm not very experienced in this) meteorcrasher118 35 — 5y

Answer this question