I’m making a minigame game. I want to make it so when all of the players die, the round ends. But I don’t know how to do so. Can anyone help me?
Here is the code:
while true do
wait(5)
local m = math.random(1,7)
local player = game.Players:GetPlayers()
for i = 1, #player do
msg = Instance.new(“Message”)
msg.Parent = nil
if m == 1 then
msg.Parent = game.Workspace
msg.Text = “Choosing minigame.”
wait(1)
msg.Text = “Choosing minigame…”
wait(1)
msg.Text = “Choosing minigame…”
wait(1)
msg.Text = “The next minigame has been chosen!”
wait(3)
msg.Text = “The minigame is…”
wait(3)
msg.Text = “Sword Wars!”
wait(2)
msg.Text = “Fight with your sword and be the last one standing to win!”
wait(1)
msg.Text = “3”
wait(1)
msg.Text = “2”
wait(1)
msg.Text = “1”
wait(1)
player[i].Character:MoveTo(Vector3.new(1860, 16.5, -1026))
msg:Destroy()
local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
ReplicatedStorage:WaitForChild(“ClassicSword”):Clone().Parent = player[i].Backpack
if m == 2 then
msg.Parent = game.Workspace
msg.Text = "Choosing mingame..."
wait(1)
msg.Text = "A minigame has been chosen!"
wait(1)
msg.Text = "The minigame is..."
wait(2)
msg.Text = "Flood Escape"
wait(1)
msg.Text = "Run quick and escape the flood and if you get touched by the water then you die!"
wait(3)
msg.Text = "3"
wait(1)
msg.Text = "2"
wait(1)
msg.Text = "1"
player[i].Character:MoveTo(Vector3.new(-4971.5, -492.5, -8323))
msg:Destroy()
wait(.5)
end
end
I whipped up some code for this, your overall goal to make it end when players die I added in there if you would rather pull that out. The method I used is a table variable and I add players to it when the round begins and then remove them from the table when they die or leave.
Code
local ReplicatedStorage = game.ReplicatedStorage
local round_interval = 10
local minimum_players_in_round = 0
local players_in_round = {}
local minigames = { --EXAMPLE: {"MiniGameName", "MiniGameDescription"}
{"Sword Wars!", "Fight with your sword and be the last one standing to win!"}
}
function get_mini_game(mini_game)
if mini_game[1] == "Sword Wars!" then
minimum_players_in_round = 1 -- Set this to 1 so that way only 1 sword fighter can be left!
for _, v in pairs(game.Players:GetChildren()) do
if v.Character and table.find(players_in_round, v.Name) then
v.Character:MoveTo(Vector3.new(1860, 16.5, -1026))
local new_sword = ReplicatedStorage:FindFirstChild("ClassicSword"):Clone()
new_sword.Parent = v.Backpack
end
end
elseif mini_game[1] == "EXAMPLE" then
--PUT MINIGAME CODE HERE
end
end
function add_players_to_round()
for _, v in pairs(game.Players:GetChildren()) do
if v.Character and v.Character:FindFirstChild("Humanoid") then
if not table.find(players_in_round, v.Name) then
table.insert(players_in_round, v.Name)
end
end
end
end
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
local humanoid = char:WaitForChild("Humanoid")
humanoid.Died:connect(function()
if table.find(players_in_round, player.Name) then
for i, p in pairs(players_in_round) do
if p == player.Name then
table.remove(players_in_round, i)
end
end
end
end)
end)
end)
game.Players.PlayerRemoving:Connect(function(player)
if table.find(players_in_round, player.Name) then
for i, p in pairs(players_in_round) do
if p == player.Name then
table.remove(players_in_round, i)
end
end
end
end)
while true do
wait(5)
local mini_game = minigames[math.random(1,#minigames)]
msg = Instance.new("Message")
msg.Parent = game.Workspace
msg.Text = "Choosing minigame."
wait(1)
msg.Text = "Choosing minigame.."
wait(1)
msg.Text = "Choosing minigame..."
wait(1)
msg.Text = "The next minigame has been chosen!"
wait(3)
msg.Text = "The minigame is..."
wait(3)
msg.Text = mini_game[1]
wait(2)
msg.Text = mini_game[2]
wait(3)
for i = 3,0,-1 do
msg.Text = tostring(i)
wait(1)
end
msg:Destroy()
add_players_to_round()
get_mini_game(mini_game)
local start_time = tick()
repeat wait() until tick() - start_time >= round_interval or #players_in_round <= minimum_players_in_round -- Makes sure either the time interval or the minimum players left is reached!
end
Hey, I was wondering if anyone here could help. Does anybody know how to make a round system where the team with the most points at the end of the game wins