-
What do you want to achieve? Keep it simple and clear!
I have a game where a random player dies every 20 seconds or so and after they die they get removed from the contestants table and when a game starts they get put into that contestants table -
What is the issue?
i have a thing where it checks if theres only 1 contestant it ends the game but it ended it when theres 2 contestants left -
What solutions have you tried so far?
I honestly have no idea of solutions to it
here is my code
RoundsModule:
local module = {}
local randomy = require(script.Parent.Game)
local status = game.ReplicatedStorage.Status
function module.i(length)
for i=length,0,-1 do
status.Value = i.." seconds left for a new round to start!"
wait(1)
end
end
local function toMS(s)
return ("%02i:%02i"):format(s/60%60, s%60)
end
function kill(contestants)
local random = randomy.Choose()
for i, v in pairs(game.Players:GetChildren()) do
if table.find(contestants, v.Name) then
table.remove(contestants,i)
end
end
workspace[random.Name].Humanoid.Health = 0
status.Value = random.Name.." died "..#contestants.." people left."
end
function module.sg(length)
local contestants = {}
for i, v in pairs(game.Players:GetPlayers()) do
--[[local tag = Instance.new("StringValue")
tag.Name = "user"
tag.Parent = v]]
table.insert(contestants, v.Name)
for i, e in pairs(workspace:GetChildren()) do
if e.Name == v.Name then
e.HumanoidRootPart.CFrame = workspace.spawn.CFrame
end
end
end
for i=length,0,-1 do
if #contestants == 1
then
game.Players[contestants[1]].leaderstats.Wins.Value = game.Players[contestants[1]].leaderstats.Wins.Value + 1
game.Players[contestants[1]].leaderstats.Coins.Value = game.Players[contestants[1]].leaderstats.Coins.Value + 25
status.Value = "Everyone died. "..contestants[1].." wins!"
wait(4)
game.Players[contestants[1]]:LoadCharacter()
break
end
if #contestants == 0
then
status.Value = "Everyone left. no-one wins."
break
end
if i == length - 1 then
status.Value = "A round of russian rouletee has begun."
wait(2)
end
if i == length - 10 then
kill(contestants)
end
if i == length - 20 then
kill(contestants)
end
if i == length - 30 then
kill(contestants)
end
if i == length - 40 then
kill(contestants)
end
if i == length - 50 then
kill(contestants)
end
if i == length - 60 then
kill(contestants)
end
if i == length - 70 then
kill(contestants)
end
if i == length - 80 then
kill(contestants)
end
if i == length - 90 then
kill(contestants)
end
if i == length - 100 then
kill(contestants)
end
status.Value = toMS(i)
wait(1)
end
end
return module
Game module
local module = {}
function module.Choose()
local randomPlayer
local randomPlayer = game.Players:GetPlayers()[math.random(1,#game.Players:GetPlayers())]
return randomPlayer
end
return module
Main script:
local r = require(script.Rounds)
local g = require(script.Game)
local plrcount = 0
game.Players.PlayerAdded:Connect(function()
plrcount = plrcount + 1
end)
game.Players.PlayerRemoving:Connect(function()
plrcount = plrcount - 1
end)
repeat
wait(1)
game.ReplicatedStorage.Status.Value = "1 more player and the game will start ("..plrcount.."/2)"
until plrcount >= 2
while wait() do
if plrcount < 2 then
repeat
wait(1)
game.ReplicatedStorage.Status.Value = "1 more player and the game will start ("..plrcount.."/2)"
until plrcount >= 2
end
r.i(10)
r.sg(120)
end
and i know that players can die even if they arent in the contestants table