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.
Please, help me fix it.
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 = 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()
else
workspace.evil:Play()
workspace.Message.Text = "All Players died! Restarting Game..."
workspace[choice.Name]:Destroy()
wait(10)
map()
end
end
end
(edited)
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, v in pairs(alive) do
if v == plr.Name then
table.remove(alive,v)
--aliveplrs = aliveplrs -1
print(plr.Name.."has been removed from the array!")
else
print("Player was not found.")
end
end
end)
end)
Have you tried moving the script into ServerScriptService? Also, are there any other scripts that run once a player enters the game? Please don’t be passive aggressive, and bumping your post like that is against forum rules.
To format it properly(if it’s not the first time), select all of the code then press “preformatted text” which is located 7th to the right of the buttons you can press.