Hello everybody! So I am making a minigame script. I made a boolvalue true on each player if they joined the minigame. And the boolvalue false if they died.
I want to make a script that makes the game end by reaching the max time or everybody died in the minigame. But it seems to be not working. I hope I get a soulution. Thank you!
The boolvalue name's is Playing.
for i = 20, 1 , -1 do wait(1) print("Time left: " .. i .. " second(s)!") end print("Game ended!") end while wait() do for i, v in pairs(game.Players:GetPlayers()) do if v.Playing.Value == false then print("Game ended!") end end end
You could also do the following:
local StillPlaying = 1 local i = 20 While i >= 0 and StillPlaying > 0 do wait(1) print("Time left: " .. i .. " second(s)!" StillPlaying = #game.Players:GetPlayers() for index, v in pairs(game.Players:GetPlayers()) do if v.Playing.Value == false then StillPlaying = StillPlaying -1 end end i = i-1 end Print("Game ended!")
in this script a "timer" ( the i variable ) will count the time left in the game. Every second the player list will be ran through to see if a boolvalue is still set to true (A player is still playing). The amount of StillPlaying is set to the amount of people in the server, and then the BoolValue is checked for every player. If the boolvalue is false, 1 is substracted from the StillPlaying Variable. When the StillPlaying variable hits 0 the game will end.
You can use coroutine.resume
to do that for you (I hope I'm wright)
Your script would become this:
coroutine.resume(function() for i = 20, 1 , -1 do wait(1) print("Time left: " .. i .. " second(s)!") end print("Game ended!") end end) coroutine.resume(function() while wait() do for i, v in pairs(game.Players:GetPlayers()) do if v.Playing.Value == false then print("Game ended!") end end end end)
I hope this works for you!