Made a game script for a remaster of R.U.N a really fun game where you run from the little balls trying to eat you. However, once 2 players are in the game, it breaks somehow. I kept trying hard to fix it, nothing worked nor helped. If all died, it counts it as a victory still. The game script is what makes the game. I really need help asap, got no response anywhere.
local alive = {}
local aliveplrs = 0
game.Players.PlayerAdded:Connect(function(plr)
print(plr.Name)
local char = plr.CharacterAdded:Wait()
char.Humanoid.Died:Connect(function()
for i = 1,#alive do
if alive[i] == plr.Name then
table.remove(alive,i)
aliveplrs = aliveplrs -1
print(plr.Name .. " has been removed from the array!")
else
print("Player was not found.")
end
end
end)
end)
function map()
workspace.Message.Text = "1 Minute til next game."
workspace.lobby:Play()
wait(3)
workspace.lobby:Stop()
workspace.Five:Play()
wait(1)
workspace.Four:Play()
wait(1)
workspace.Three:Play()
wait(1)
workspace.Two:Play()
wait(1)
workspace.One:Play()
wait(1)
workspace.freshmeat:Play()
for i,v in pairs(game.Players:GetPlayers()) do
v.Character.HumanoidRootPart.Position = Vector3.new(0, 40, -64)
table.insert(alive,v.Name)
aliveplrs = i
workspace.Message.Text = "A game is in progress."
v.TeamColor = game.Teams.Alive.TeamColor
local maps = game.Lighting.Maps:GetChildren()
local choice = maps[math.random(1,#maps)]
choice:Clone().Parent = workspace
wait(40)
if aliveplrs >0 then
workspace.cheer:Play()
workspace.Message.Text = "Game Ended. Restarting..."
workspace[choice.Name]:Destroy()
wait(10)
map()
aliveplrs = 0
else
workspace.evil:Play()
workspace.Message.Text = "All Players died! Restarting Game..."
workspace[choice.Name]:Destroy()
wait(10)
map()
aliveplrs = 0
end
end
end
map()
