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

How to run these thingy at the same time?

Asked by 5 years ago

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
0
Try seperating script. Cuz u cant run those in the same time in one script. AswormeDorijan111 531 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

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.

0
thank you very much! A_nsonn 4 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

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!

Answer this question