--Irvin
--This is a test version of the script
--You can edit these variables.
waitTeam = "Bright green" -- The team for the waiting room.
waitTime = 30 -- The time spent in the waiting room before battle.
battleTeam = "Bright yellow" -- The team for the battle arena.
battleTime = 180 -- The amount of time the battle will last.
winBonus = 5 --The KO bonus given to the last man standing.
tieBonus = 1 --If more than 1 player is left standing, then this will be added to the standing player's KOs.
--Only I should edit things beyond this point.
battle = false
function onDiedInBattle(humanoid, player)
local stats = player:findFirstChild("leaderstats")
if stats ~= nil and battle==true then
local deaths = stats:findFirstChild("Wipeouts")
deaths.Value = deaths.Value + 1
player.TeamColor = BrickColor.new(waitTeam)
print("Player died")
-- do short dance to try and find the killer
local killer = getKillerOfHumanoidIfStillInGame(humanoid)
handleKillCount(humanoid, player)
local playersStillInBattle = {}
for i,child in pairs(game.Players:getChildren()) do
if child.TeamColor == BrickColor.new(battleTeam) then
table.insert(playersStillInBattle, child)
end
end
if #playersStillInBattle <= 1 then
battle = false
message("All players have been eliminated!", 2)
nameWinner()
changePlayersToTeamColor(waitTeam)
killAllPlayers()
end
end
end
function getKillerOfHumanoidIfStillInGame(humanoid)
-- returns the player object that killed this humanoid
-- returns nil if the killer is no longer in the game
-- check for kill tag on humanoid - may be more than one - todo: deal with this
local tag = humanoid:findFirstChild("creator")
-- find player with name on tag
if tag ~= nil then
local killer = tag.Value
if killer.Parent ~= nil then -- killer still in game
return killer
end
end
return nil
end
function handleKillCount(humanoid, player)
local killer = getKillerOfHumanoidIfStillInGame(humanoid)
if killer ~= nil then
local stats = killer:findFirstChild("leaderstats")
if stats ~= nil then
local kills = stats:findFirstChild("KOs")
if killer ~= player then
kills.Value = kills.Value + 1
else
kills.Value = kills.Value - 1
end
end
end
end
-----------------------------------------------
function onPlayerEntered(newPlayer)
wait()
local kills = Instance.new("IntValue")
kills.Name = "KOs"
kills.Value = 0
local deaths = Instance.new("IntValue")
deaths.Name = "Wipeouts"
deaths.Value = 0
-- VERY UGLY HACK
-- Will this leak threads?
-- Is the problem even what I think it is (player arrived before character)?
while true do
if newPlayer.Character ~= nil then break end
wait(5)
end
newPlayer.Changed:connect(
function(property)
if property == "Character" and newPlayer.TeamColor ~= BrickColor.new(battleTeam) then
print("Player spawned, removing tools")
for i,tool in pairs(newPlayer.Backpack:getChildren()) do
if tool.className == "Tool" or tool.className == "HopperBin" then
tool:remove()
end
end
end
end
)
if newPlayer:findFirstChild("leaderstats") == nil then
local stats = Instance.new("IntValue")
stats.Name = "leaderstats"
kills.Parent = stats
deaths.Parent = stats
stats.Parent = newPlayer
else
kills.Parent = newPlayer.leaderstats
deaths.Parent = newPlayer.leaderstats
end
newPlayer.TeamColor = BrickColor.new(waitTeam)
for i,tool in pairs(newPlayer.Backpack:getChildren()) do
if tool.className == "Tool" or tool.className == "HopperBin" then
tool:remove()
end
end
end
game.Players.ChildAdded:connect(onPlayerEntered)
function changePlayersToTeamColor(color)
for i, player in pairs(game.Players:getChildren()) do
if player.Neutral == true then
player.Neutral = false
end
player.TeamColor = BrickColor.new(color)
end
end
function killAllPlayers()
for i, player in pairs(game.Players:getChildren()) do
player.Character.Humanoid.Health = 0
end
end
function beginBattle()
for i, player in pairs(game.Players:getChildren()) do
if player.Character.Humanoid.Health <= 0 then
while true do
if player.Character ~= nil then
if player.Character.Humanoid.Health >= 0 then break end
end
wait()
end
end
print(player.Name.." is now ready for battle.")
player.Character.Humanoid.Died:connect(function() onDiedInBattle(player.Character.Humanoid, player) end)
end
end
function nameWinner()
local winners = {}
function getWinners()
for i,player in pairs(game.Players:getChildren()) do
if player.TeamColor == BrickColor.new(battleTeam) then
table.insert(winners, player)
end
end
end
getWinners()
if #winners == 1 then
winners[1].leaderstats.KOs.Value = winners[1].leaderstats.KOs.Value + winBonus
elseif #winners > 1 then
for i=1, #winners do
winners[i].leaderstats.KOs.Value = winners[i].leaderstats.KOs.Value + tieBonus
end
end
if #winners == 1 then
message("The winner of this game was "..winners[1].Name..".", 3)
elseif #winners == 0 then
message("Everyone died in this game.", 3)
elseif #winners == 2 then
message("The game was tied between "..winners[1].Name.." and "..winners[2].Name..".", 3)
elseif #winners > 2 then
string = "This game was tied between "
for i=1, #winners - 1 do
string = string..winners[i].Name..", "
end
string = string.."and "..winners[#winners].Name.."."
message(string, 3)
end
end
while true do
message("Game will begin in "..waitTime.." seconds!" , 3)
wait(waitTime)
changePlayersToTeamColor(battleTeam)
killAllPlayers()
message("Let the battle begin!", 3)
message("The battle will last "..(battleTime/60).." minutes!", 2)
wait(0.25)
battle = true
beginBattle()
local btime = 0
while battle == true do
btime = btime + 1
if btime >= battleTime or not battle then break end
wait(1)
end
print(btime)
if battle == true then
battle = false
message("The battle is now over.", 2)
nameWinner()
changePlayersToTeamColor(waitTeam)
killAllPlayers()
else
wait(2)
end
wait(5.1)
end
Both Colors are set to AutoAssignable when a player joins the green color is in the lobby and yellow is spread across the map but for some reason player 1 goes to the lobby and player 2 spawns in the map already I have tested this in Roblox Studio but it wont work I tried to set yellow team AutoAssignable to false and player 1 and 2 will spawn at the lobby but they wont change their positions to the game after 30 seconds they both stay in the lobby I dont know what else to try please help ??

3 comments
Did you put an actual spawn for the maps? If so, don't.
Yes I put the spawn bricks green on lobby and yellow in the map, If i take out the spawn bricks how will the players spawn?
Do I take both spawn bricks out or just the Yellow, I only have one map which will be the arena, I took both of the SpawnBricks out and both spawned in the green color but not inside the lobby, Maybe is it because I took the green Spawn bricks out of the lobby and deleted them ? Help and Thank You :)