Already worked! Thanks so much for your help
No problem, I think the script could be made a bit better by using a for loop to loop between teams instead of doing them all yourself, but this one works, so there isn’t a need. You could also make a function for checking the teams, but no need.
If you need more help, feel free to ask (even though I’m a beginner scripter too).
Okay, Thanks for the advice.
Oh really! Thanks!!
@craftingboy26 , Hello again.
Sorry for disturbing you but, My system doesn’t work with multiple players…
As you can see, I made a LOT of changes into my system, here’s the code:
local teams = game:GetService("Teams")
local redTeam = teams:WaitForChild("Red")
local blueTeam = teams:WaitForChild("Blue")
local greenTeam = teams:WaitForChild("Green")
local yellowTeam = teams:WaitForChild("Yellow")
game.ReplicatedStorage.Events.RemoveFromTeam.OnServerEvent:Connect(function(player)
game.Teams:FindFirstChild(player.Team.Name):Destroy()
player.TeamColor = BrickColor.new("Medium stone grey") -- spectators
end)
game.Teams:WaitForChild("Red").PlayerRemoved:Connect(function(player)
if #game.Teams:WaitForChild("Red"):GetPlayers() == 0 and game.Teams:WaitForChild("Red").EggBroken.Value == true then
game.Teams:WaitForChild("Red"):Destroy()
player.TeamColor = BrickColor.new("Medium stone grey") -- spectators
end
end)
blueTeam.PlayerRemoved:Connect(function(player)
if #blueTeam:GetPlayers() ==0 and blueTeam.EggBroken.Value == true then
blueTeam:Destroy()
player.TeamColor = BrickColor.new("Medium stone grey") -- spectators
end
end)
yellowTeam.PlayerRemoved:Connect(function(player)
if #yellowTeam:GetPlayers() ==0 and yellowTeam.EggBroken.Value == true then
yellowTeam:Destroy()
player.TeamColor = BrickColor.new("Medium stone grey") -- spectators
end
end)
greenTeam.PlayerRemoved:Connect(function(player)
if #greenTeam:GetPlayers() ==0 and greenTeam.EggBroken.Value == true then
greenTeam:Destroy()
player.TeamColor = BrickColor.new("Medium stone grey") -- spectators
end
end)
local plr
game.Players.PlayerAdded:Connect(function(player)
plr = player
game.ReplicatedStorage.Intermission.MatchStarted:GetPropertyChangedSignal("Value"):Connect(function()
if game.ReplicatedStorage.Intermission.MatchStarted.Value == true then
task.wait(0.01)
if player.Team == game.Teams:WaitForChild("Red") then -- player is on the red team, same applies for all.
if #game.Teams:WaitForChild("Red"):GetPlayers() >= 1 and #greenTeam:GetPlayers() == 0 and #blueTeam:GetPlayers() == 0 and #yellowTeam:GetPlayers() == 0 and yellowTeam.EggBroken.Value == true and blueTeam.EggBroken.Value == true and greenTeam.EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(player)
end
end
if player.Team == greenTeam then -- player is on the red team, same applies for all.
if #greenTeam:GetPlayers() >= 1 and #game.Teams:WaitForChild("Red"):GetPlayers() == 0 and #blueTeam:GetPlayers() == 0 and #yellowTeam:GetPlayers() == 0 and blueTeam.EggBroken.Value == true and yellowTeam.EggBroken.Value == true and game.Teams:WaitForChild("Red").EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(player)
end
end
if player.Team == blueTeam then -- player is on the red team, same applies for all.
if #blueTeam:GetPlayers() >= 1 and #game.Teams:WaitForChild("Red"):GetPlayers() == 0 and #greenTeam:GetPlayers() == 0 and #yellowTeam:GetPlayers() == 0 and yellowTeam.EggBroken.Value == true and game.Teams:WaitForChild("Red").EggBroken.Value == true and greenTeam.EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(player)
end
end
if player.Team == yellowTeam then -- player is on the red team, same applies for all.
if #yellowTeam:GetPlayers() >= 1 and #greenTeam:GetPlayers() == 0 and #blueTeam:GetPlayers() == 0 and #game.Teams:WaitForChild("Red"):GetPlayers() == 0 and game.Teams:WaitForChild("Red").EggBroken.Value == true and blueTeam.EggBroken.Value == true and greenTeam.EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(player)
end
end
end
game.Teams:WaitForChild("Red").PlayerRemoved:Connect(function()
task.wait(0.01)
if player.Team == game.Teams:WaitForChild("Red") then -- player is on the red team, same applies for all.
if #game.Teams:WaitForChild("Red"):GetPlayers() >= 1 and #greenTeam:GetPlayers() == 0 and #blueTeam:GetPlayers() == 0 and #yellowTeam:GetPlayers() == 0 and yellowTeam.EggBroken.Value == true and blueTeam.EggBroken.Value == true and greenTeam.EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(player)
end
end
if player.Team == greenTeam then -- player is on the red team, same applies for all.
if #greenTeam:GetPlayers() >= 1 and #game.Teams:WaitForChild("Red"):GetPlayers() == 0 and #blueTeam:GetPlayers() == 0 and #yellowTeam:GetPlayers() == 0 and blueTeam.EggBroken.Value == true and yellowTeam.EggBroken.Value == true and game.Teams:WaitForChild("Red").EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(player)
end
end
if player.Team == blueTeam then -- player is on the red team, same applies for all.
if #blueTeam:GetPlayers() >= 1 and #game.Teams:WaitForChild("Red"):GetPlayers() == 0 and #greenTeam:GetPlayers() == 0 and #yellowTeam:GetPlayers() == 0 and yellowTeam.EggBroken.Value == true and game.Teams:WaitForChild("Red").EggBroken.Value == true and greenTeam.EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(player)
end
end
if player.Team == yellowTeam then -- player is on the red team, same applies for all.
if #yellowTeam:GetPlayers() >= 1 and #greenTeam:GetPlayers() == 0 and #blueTeam:GetPlayers() == 0 and #game.Teams:WaitForChild("Red"):GetPlayers() == 0 and game.Teams:WaitForChild("Red").EggBroken.Value == true and blueTeam.EggBroken.Value == true and greenTeam.EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(player)
end
end
end)
greenTeam.PlayerRemoved:Connect(function()
task.wait(0.01)
if player.Team == game.Teams:WaitForChild("Red") then -- player is on the red team, same applies for all.
if #game.Teams:WaitForChild("Red"):GetPlayers() >= 1 and #greenTeam:GetPlayers() == 0 and #blueTeam:GetPlayers() == 0 and #yellowTeam:GetPlayers() == 0 and yellowTeam.EggBroken.Value == true and blueTeam.EggBroken.Value == true and greenTeam.EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(player)
end
end
if player.Team == greenTeam then -- player is on the red team, same applies for all.
if #greenTeam:GetPlayers() >= 1 and #game.Teams:WaitForChild("Red"):GetPlayers() == 0 and #blueTeam:GetPlayers() == 0 and #yellowTeam:GetPlayers() == 0 and blueTeam.EggBroken.Value == true and yellowTeam.EggBroken.Value == true and game.Teams:WaitForChild("Red").EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(player)
end
end
if player.Team == blueTeam then -- player is on the red team, same applies for all.
if #blueTeam:GetPlayers() >= 1 and #game.Teams:WaitForChild("Red"):GetPlayers() == 0 and #greenTeam:GetPlayers() == 0 and #yellowTeam:GetPlayers() == 0 and yellowTeam.EggBroken.Value == true and game.Teams:WaitForChild("Red").EggBroken.Value == true and greenTeam.EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(player)
end
end
if player.Team == yellowTeam then -- player is on the red team, same applies for all.
if #yellowTeam:GetPlayers() >= 1 and #greenTeam:GetPlayers() == 0 and #blueTeam:GetPlayers() == 0 and #game.Teams:WaitForChild("Red"):GetPlayers() == 0 and game.Teams:WaitForChild("Red").EggBroken.Value == true and blueTeam.EggBroken.Value == true and greenTeam.EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(player)
end
end
end)
yellowTeam.PlayerRemoved:Connect(function()
task.wait(0.01)
if player.Team == game.Teams:WaitForChild("Red") then -- player is on the red team, same applies for all.
if #game.Teams:WaitForChild("Red"):GetPlayers() >= 1 and #greenTeam:GetPlayers() == 0 and #blueTeam:GetPlayers() == 0 and #yellowTeam:GetPlayers() == 0 and yellowTeam.EggBroken.Value == true and blueTeam.EggBroken.Value == true and greenTeam.EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(player)
end
end
if player.Team == greenTeam then -- player is on the red team, same applies for all.
if #greenTeam:GetPlayers() >= 1 and #game.Teams:WaitForChild("Red"):GetPlayers() == 0 and #blueTeam:GetPlayers() == 0 and #yellowTeam:GetPlayers() == 0 and blueTeam.EggBroken.Value == true and yellowTeam.EggBroken.Value == true and game.Teams:WaitForChild("Red").EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(player)
end
end
if player.Team == blueTeam then -- player is on the red team, same applies for all.
if #blueTeam:GetPlayers() >= 1 and #game.Teams:WaitForChild("Red"):GetPlayers() == 0 and #greenTeam:GetPlayers() == 0 and #yellowTeam:GetPlayers() == 0 and yellowTeam.EggBroken.Value == true and game.Teams:WaitForChild("Red").EggBroken.Value == true and greenTeam.EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(player)
end
end
if player.Team == yellowTeam then -- player is on the red team, same applies for all.
if #yellowTeam:GetPlayers() >= 1 and #greenTeam:GetPlayers() == 0 and #blueTeam:GetPlayers() == 0 and #game.Teams:WaitForChild("Red"):GetPlayers() == 0 and game.Teams:WaitForChild("Red").EggBroken.Value == true and blueTeam.EggBroken.Value == true and greenTeam.EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(player)
end
end
end)
blueTeam.PlayerRemoved:Connect(function()
task.wait(0.01)
if player.Team == game.Teams:WaitForChild("Red") then -- player is on the red team, same applies for all.
if #game.Teams:WaitForChild("Red"):GetPlayers() >= 1 and #greenTeam:GetPlayers() == 0 and #blueTeam:GetPlayers() == 0 and #yellowTeam:GetPlayers() == 0 and yellowTeam.EggBroken.Value == true and blueTeam.EggBroken.Value == true and greenTeam.EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(player)
end
end
if player.Team == greenTeam then -- player is on the red team, same applies for all.
if #greenTeam:GetPlayers() >= 1 and #game.Teams:WaitForChild("Red"):GetPlayers() == 0 and #blueTeam:GetPlayers() == 0 and #yellowTeam:GetPlayers() == 0 and blueTeam.EggBroken.Value == true and yellowTeam.EggBroken.Value == true and game.Teams:WaitForChild("Red").EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(player)
end
end
if player.Team == blueTeam then -- player is on the red team, same applies for all.
if #blueTeam:GetPlayers() >= 1 and #game.Teams:WaitForChild("Red"):GetPlayers() == 0 and #greenTeam:GetPlayers() == 0 and #yellowTeam:GetPlayers() == 0 and yellowTeam.EggBroken.Value == true and game.Teams:WaitForChild("Red").EggBroken.Value == true and greenTeam.EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(player)
end
end
if player.Team == yellowTeam then -- player is on the red team, same applies for all.
if #yellowTeam:GetPlayers() >= 1 and #greenTeam:GetPlayers() == 0 and #blueTeam:GetPlayers() == 0 and #game.Teams:WaitForChild("Red"):GetPlayers() == 0 and game.Teams:WaitForChild("Red").EggBroken.Value == true and blueTeam.EggBroken.Value == true and greenTeam.EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(player)
end
end
end)
game.Teams:WaitForChild("Red").EggBroken:GetPropertyChangedSignal("Value"):Connect(function()
task.wait(0.01)
if player.Team == game.Teams:WaitForChild("Red") then -- player is on the red team, same applies for all.
if #game.Teams:WaitForChild("Red"):GetPlayers() >= 1 and #greenTeam:GetPlayers() == 0 and #blueTeam:GetPlayers() == 0 and #yellowTeam:GetPlayers() == 0 and yellowTeam.EggBroken.Value == true and blueTeam.EggBroken.Value == true and greenTeam.EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(player)
end
end
if player.Team == greenTeam then -- player is on the red team, same applies for all.
if #greenTeam:GetPlayers() >= 1 and #game.Teams:WaitForChild("Red"):GetPlayers() == 0 and #blueTeam:GetPlayers() == 0 and #yellowTeam:GetPlayers() == 0 and blueTeam.EggBroken.Value == true and yellowTeam.EggBroken.Value == true and game.Teams:WaitForChild("Red").EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(player)
end
end
if player.Team == blueTeam then -- player is on the red team, same applies for all.
if #blueTeam:GetPlayers() >= 1 and #game.Teams:WaitForChild("Red"):GetPlayers() == 0 and #greenTeam:GetPlayers() == 0 and #yellowTeam:GetPlayers() == 0 and yellowTeam.EggBroken.Value == true and game.Teams:WaitForChild("Red").EggBroken.Value == true and greenTeam.EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(player)
end
end
if player.Team == yellowTeam then -- player is on the red team, same applies for all.
if #yellowTeam:GetPlayers() >= 1 and #greenTeam:GetPlayers() == 0 and #blueTeam:GetPlayers() == 0 and #game.Teams:WaitForChild("Red"):GetPlayers() == 0 and game.Teams:WaitForChild("Red").EggBroken.Value == true and blueTeam.EggBroken.Value == true and greenTeam.EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(player)
end
end
end)
greenTeam.EggBroken:GetPropertyChangedSignal("Value"):Connect(function()
task.wait(0.01)
if player.Team == game.Teams:WaitForChild("Red") then -- player is on the red team, same applies for all.
if #game.Teams:WaitForChild("Red"):GetPlayers() >= 1 and #greenTeam:GetPlayers() == 0 and #blueTeam:GetPlayers() == 0 and #yellowTeam:GetPlayers() == 0 and yellowTeam.EggBroken.Value == true and blueTeam.EggBroken.Value == true and greenTeam.EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(player)
end
end
if player.Team == greenTeam then -- player is on the red team, same applies for all.
if #greenTeam:GetPlayers() >= 1 and #game.Teams:WaitForChild("Red"):GetPlayers() == 0 and #blueTeam:GetPlayers() == 0 and #yellowTeam:GetPlayers() == 0 and blueTeam.EggBroken.Value == true and yellowTeam.EggBroken.Value == true and game.Teams:WaitForChild("Red").EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(player)
end
end
if player.Team == blueTeam then -- player is on the red team, same applies for all.
if #blueTeam:GetPlayers() >= 1 and #game.Teams:WaitForChild("Red"):GetPlayers() == 0 and #greenTeam:GetPlayers() == 0 and #yellowTeam:GetPlayers() == 0 and yellowTeam.EggBroken.Value == true and game.Teams:WaitForChild("Red").EggBroken.Value == true and greenTeam.EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(player)
end
end
if player.Team == yellowTeam then -- player is on the red team, same applies for all.
if #yellowTeam:GetPlayers() >= 1 and #greenTeam:GetPlayers() == 0 and #blueTeam:GetPlayers() == 0 and #game.Teams:WaitForChild("Red"):GetPlayers() == 0 and game.Teams:WaitForChild("Red").EggBroken.Value == true and blueTeam.EggBroken.Value == true and greenTeam.EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(player)
end
end
end)
blueTeam.EggBroken:GetPropertyChangedSignal("Value"):Connect(function()
task.wait(0.01)
if player.Team == game.Teams:WaitForChild("Red") then -- player is on the red team, same applies for all.
if #game.Teams:WaitForChild("Red"):GetPlayers() >= 1 and #greenTeam:GetPlayers() == 0 and #blueTeam:GetPlayers() == 0 and #yellowTeam:GetPlayers() == 0 and yellowTeam.EggBroken.Value == true and blueTeam.EggBroken.Value == true and greenTeam.EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(player)
end
end
if player.Team == greenTeam then -- player is on the red team, same applies for all.
if #greenTeam:GetPlayers() >= 1 and #game.Teams:WaitForChild("Red"):GetPlayers() == 0 and #blueTeam:GetPlayers() == 0 and #yellowTeam:GetPlayers() == 0 and blueTeam.EggBroken.Value == true and yellowTeam.EggBroken.Value == true and game.Teams:WaitForChild("Red").EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(player)
end
end
if player.Team == blueTeam then -- player is on the red team, same applies for all.
if #blueTeam:GetPlayers() >= 1 and #game.Teams:WaitForChild("Red"):GetPlayers() == 0 and #greenTeam:GetPlayers() == 0 and #yellowTeam:GetPlayers() == 0 and yellowTeam.EggBroken.Value == true and game.Teams:WaitForChild("Red").EggBroken.Value == true and greenTeam.EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(player)
end
end
if player.Team == yellowTeam then -- player is on the red team, same applies for all.
if #yellowTeam:GetPlayers() >= 1 and #greenTeam:GetPlayers() == 0 and #blueTeam:GetPlayers() == 0 and #game.Teams:WaitForChild("Red"):GetPlayers() == 0 and game.Teams:WaitForChild("Red").EggBroken.Value == true and blueTeam.EggBroken.Value == true and greenTeam.EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(player)
end
end
end)
yellowTeam.EggBroken:GetPropertyChangedSignal("Value"):Connect(function()
task.wait(0.01)
if player.Team == game.Teams:WaitForChild("Red") then -- player is on the red team, same applies for all.
if #game.Teams:WaitForChild("Red"):GetPlayers() >= 1 and #greenTeam:GetPlayers() == 0 and #blueTeam:GetPlayers() == 0 and #yellowTeam:GetPlayers() == 0 and yellowTeam.EggBroken.Value == true and blueTeam.EggBroken.Value == true and greenTeam.EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(player)
end
end
if player.Team == greenTeam then -- player is on the red team, same applies for all.
if #greenTeam:GetPlayers() >= 1 and #game.Teams:WaitForChild("Red"):GetPlayers() == 0 and #blueTeam:GetPlayers() == 0 and #yellowTeam:GetPlayers() == 0 and blueTeam.EggBroken.Value == true and yellowTeam.EggBroken.Value == true and game.Teams:WaitForChild("Red").EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(player)
end
end
if player.Team == blueTeam then -- player is on the red team, same applies for all.
if #blueTeam:GetPlayers() >= 1 and #game.Teams:WaitForChild("Red"):GetPlayers() == 0 and #greenTeam:GetPlayers() == 0 and #yellowTeam:GetPlayers() == 0 and yellowTeam.EggBroken.Value == true and game.Teams:WaitForChild("Red").EggBroken.Value == true and greenTeam.EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(player)
end
end
if player.Team == yellowTeam then -- player is on the red team, same applies for all.
if #yellowTeam:GetPlayers() >= 1 and #greenTeam:GetPlayers() == 0 and #blueTeam:GetPlayers() == 0 and #game.Teams:WaitForChild("Red"):GetPlayers() == 0 and game.Teams:WaitForChild("Red").EggBroken.Value == true and blueTeam.EggBroken.Value == true and greenTeam.EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(player)
end
end
end)
end)
end)
game.Teams:WaitForChild("Red").PlayerRemoved:Connect(function()
task.wait(0.01)
if plr.Team == game.Teams:WaitForChild("Red") then -- player is on the red team, same applies for all.
if #game.Teams:WaitForChild("Red"):GetPlayers() >= 1 and #greenTeam:GetPlayers() == 0 and #blueTeam:GetPlayers() == 0 and #yellowTeam:GetPlayers() == 0 and yellowTeam.EggBroken.Value == true and blueTeam.EggBroken.Value == true and greenTeam.EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(plr)
end
end
if plr.Team == greenTeam then -- player is on the red team, same applies for all.
if #greenTeam:GetPlayers() >= 1 and #game.Teams:WaitForChild("Red"):GetPlayers() == 0 and #blueTeam:GetPlayers() == 0 and #yellowTeam:GetPlayers() == 0 and blueTeam.EggBroken.Value == true and yellowTeam.EggBroken.Value == true and game.Teams:WaitForChild("Red").EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(plr)
end
end
if plr.Team == blueTeam then -- player is on the red team, same applies for all.
if #blueTeam:GetPlayers() >= 1 and #game.Teams:WaitForChild("Red"):GetPlayers() == 0 and #greenTeam:GetPlayers() == 0 and #yellowTeam:GetPlayers() == 0 and yellowTeam.EggBroken.Value == true and game.Teams:WaitForChild("Red").EggBroken.Value == true and greenTeam.EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(plr)
end
end
if plr.Team == yellowTeam then -- player is on the red team, same applies for all.
if #yellowTeam:GetPlayers() >= 1 and #greenTeam:GetPlayers() == 0 and #blueTeam:GetPlayers() == 0 and #game.Teams:WaitForChild("Red"):GetPlayers() == 0 and game.Teams:WaitForChild("Red").EggBroken.Value == true and blueTeam.EggBroken.Value == true and greenTeam.EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(plr)
end
end
end)
greenTeam.PlayerRemoved:Connect(function()
task.wait(0.01)
if plr.Team == game.Teams:WaitForChild("Red") then -- player is on the red team, same applies for all.
if #game.Teams:WaitForChild("Red"):GetPlayers() >= 1 and #greenTeam:GetPlayers() == 0 and #blueTeam:GetPlayers() == 0 and #yellowTeam:GetPlayers() == 0 and yellowTeam.EggBroken.Value == true and blueTeam.EggBroken.Value == true and greenTeam.EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(plr)
end
end
if plr.Team == greenTeam then -- player is on the red team, same applies for all.
if #greenTeam:GetPlayers() >= 1 and #game.Teams:WaitForChild("Red"):GetPlayers() == 0 and #blueTeam:GetPlayers() == 0 and #yellowTeam:GetPlayers() == 0 and blueTeam.EggBroken.Value == true and yellowTeam.EggBroken.Value == true and game.Teams:WaitForChild("Red").EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(plr)
end
end
if plr.Team == blueTeam then -- player is on the red team, same applies for all.
if #blueTeam:GetPlayers() >= 1 and #game.Teams:WaitForChild("Red"):GetPlayers() == 0 and #greenTeam:GetPlayers() == 0 and #yellowTeam:GetPlayers() == 0 and yellowTeam.EggBroken.Value == true and game.Teams:WaitForChild("Red").EggBroken.Value == true and greenTeam.EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(plr)
end
end
if plr.Team == yellowTeam then -- player is on the red team, same applies for all.
if #yellowTeam:GetPlayers() >= 1 and #greenTeam:GetPlayers() == 0 and #blueTeam:GetPlayers() == 0 and #game.Teams:WaitForChild("Red"):GetPlayers() == 0 and game.Teams:WaitForChild("Red").EggBroken.Value == true and blueTeam.EggBroken.Value == true and greenTeam.EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(plr)
end
end
end)
yellowTeam.PlayerRemoved:Connect(function()
task.wait(0.01)
if plr.Team == game.Teams:WaitForChild("Red") then -- player is on the red team, same applies for all.
if #game.Teams:WaitForChild("Red"):GetPlayers() >= 1 and #greenTeam:GetPlayers() == 0 and #blueTeam:GetPlayers() == 0 and #yellowTeam:GetPlayers() == 0 and yellowTeam.EggBroken.Value == true and blueTeam.EggBroken.Value == true and greenTeam.EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(plr)
end
end
if plr.Team == greenTeam then -- player is on the red team, same applies for all.
if #greenTeam:GetPlayers() >= 1 and #game.Teams:WaitForChild("Red"):GetPlayers() == 0 and #blueTeam:GetPlayers() == 0 and #yellowTeam:GetPlayers() == 0 and blueTeam.EggBroken.Value == true and yellowTeam.EggBroken.Value == true and game.Teams:WaitForChild("Red").EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(plr)
end
end
if plr.Team == blueTeam then -- player is on the red team, same applies for all.
if #blueTeam:GetPlayers() >= 1 and #game.Teams:WaitForChild("Red"):GetPlayers() == 0 and #greenTeam:GetPlayers() == 0 and #yellowTeam:GetPlayers() == 0 and yellowTeam.EggBroken.Value == true and game.Teams:WaitForChild("Red").EggBroken.Value == true and greenTeam.EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(plr)
end
end
if plr.Team == yellowTeam then -- player is on the red team, same applies for all.
if #yellowTeam:GetPlayers() >= 1 and #greenTeam:GetPlayers() == 0 and #blueTeam:GetPlayers() == 0 and #game.Teams:WaitForChild("Red"):GetPlayers() == 0 and game.Teams:WaitForChild("Red").EggBroken.Value == true and blueTeam.EggBroken.Value == true and greenTeam.EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(plr)
end
end
end)
blueTeam.PlayerRemoved:Connect(function()
task.wait(0.01)
if plr.Team == game.Teams:WaitForChild("Red") then -- player is on the red team, same applies for all.
if #game.Teams:WaitForChild("Red"):GetPlayers() >= 1 and #greenTeam:GetPlayers() == 0 and #blueTeam:GetPlayers() == 0 and #yellowTeam:GetPlayers() == 0 and yellowTeam.EggBroken.Value == true and blueTeam.EggBroken.Value == true and greenTeam.EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(plr)
end
end
if plr.Team == greenTeam then -- player is on the red team, same applies for all.
if #greenTeam:GetPlayers() >= 1 and #game.Teams:WaitForChild("Red"):GetPlayers() == 0 and #blueTeam:GetPlayers() == 0 and #yellowTeam:GetPlayers() == 0 and blueTeam.EggBroken.Value == true and yellowTeam.EggBroken.Value == true and game.Teams:WaitForChild("Red").EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(plr)
end
end
if plr.Team == blueTeam then -- player is on the red team, same applies for all.
if #blueTeam:GetPlayers() >= 1 and #game.Teams:WaitForChild("Red"):GetPlayers() == 0 and #greenTeam:GetPlayers() == 0 and #yellowTeam:GetPlayers() == 0 and yellowTeam.EggBroken.Value == true and game.Teams:WaitForChild("Red").EggBroken.Value == true and greenTeam.EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(plr)
end
end
if plr.Team == yellowTeam then -- player is on the red team, same applies for all.
if #yellowTeam:GetPlayers() >= 1 and #greenTeam:GetPlayers() == 0 and #blueTeam:GetPlayers() == 0 and #game.Teams:WaitForChild("Red"):GetPlayers() == 0 and game.Teams:WaitForChild("Red").EggBroken.Value == true and blueTeam.EggBroken.Value == true and greenTeam.EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(plr)
end
end
end)
game.Teams:WaitForChild("Red").EggBroken:GetPropertyChangedSignal("Value"):Connect(function()
task.wait(0.01)
if plr.Team == game.Teams:WaitForChild("Red") then -- player is on the red team, same applies for all.
if #game.Teams:WaitForChild("Red"):GetPlayers() >= 1 and #greenTeam:GetPlayers() == 0 and #blueTeam:GetPlayers() == 0 and #yellowTeam:GetPlayers() == 0 and yellowTeam.EggBroken.Value == true and blueTeam.EggBroken.Value == true and greenTeam.EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(plr)
end
end
if plr.Team == greenTeam then -- player is on the red team, same applies for all.
if #greenTeam:GetPlayers() >= 1 and #game.Teams:WaitForChild("Red"):GetPlayers() == 0 and #blueTeam:GetPlayers() == 0 and #yellowTeam:GetPlayers() == 0 and blueTeam.EggBroken.Value == true and yellowTeam.EggBroken.Value == true and game.Teams:WaitForChild("Red").EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(plr)
end
end
if plr.Team == blueTeam then -- player is on the red team, same applies for all.
if #blueTeam:GetPlayers() >= 1 and #game.Teams:WaitForChild("Red"):GetPlayers() == 0 and #greenTeam:GetPlayers() == 0 and #yellowTeam:GetPlayers() == 0 and yellowTeam.EggBroken.Value == true and game.Teams:WaitForChild("Red").EggBroken.Value == true and greenTeam.EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(plr)
end
end
if plr.Team == yellowTeam then -- player is on the red team, same applies for all.
if #yellowTeam:GetPlayers() >= 1 and #greenTeam:GetPlayers() == 0 and #blueTeam:GetPlayers() == 0 and #game.Teams:WaitForChild("Red"):GetPlayers() == 0 and game.Teams:WaitForChild("Red").EggBroken.Value == true and blueTeam.EggBroken.Value == true and greenTeam.EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(plr)
end
end
end)
greenTeam.EggBroken:GetPropertyChangedSignal("Value"):Connect(function()
task.wait(0.01)
if plr.Team == game.Teams:WaitForChild("Red") then -- player is on the red team, same applies for all.
if #game.Teams:WaitForChild("Red"):GetPlayers() >= 1 and #greenTeam:GetPlayers() == 0 and #blueTeam:GetPlayers() == 0 and #yellowTeam:GetPlayers() == 0 and yellowTeam.EggBroken.Value == true and blueTeam.EggBroken.Value == true and greenTeam.EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(plr)
end
end
if plr.Team == greenTeam then -- player is on the red team, same applies for all.
if #greenTeam:GetPlayers() >= 1 and #game.Teams:WaitForChild("Red"):GetPlayers() == 0 and #blueTeam:GetPlayers() == 0 and #yellowTeam:GetPlayers() == 0 and blueTeam.EggBroken.Value == true and yellowTeam.EggBroken.Value == true and game.Teams:WaitForChild("Red").EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(plr)
end
end
if plr.Team == blueTeam then -- player is on the red team, same applies for all.
if #blueTeam:GetPlayers() >= 1 and #game.Teams:WaitForChild("Red"):GetPlayers() == 0 and #greenTeam:GetPlayers() == 0 and #yellowTeam:GetPlayers() == 0 and yellowTeam.EggBroken.Value == true and game.Teams:WaitForChild("Red").EggBroken.Value == true and greenTeam.EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(plr)
end
end
if plr.Team == yellowTeam then -- player is on the red team, same applies for all.
if #yellowTeam:GetPlayers() >= 1 and #greenTeam:GetPlayers() == 0 and #blueTeam:GetPlayers() == 0 and #game.Teams:WaitForChild("Red"):GetPlayers() == 0 and game.Teams:WaitForChild("Red").EggBroken.Value == true and blueTeam.EggBroken.Value == true and greenTeam.EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(plr)
end
end
end)
blueTeam.EggBroken:GetPropertyChangedSignal("Value"):Connect(function()
task.wait(0.01)
if plr.Team == game.Teams:WaitForChild("Red") then -- player is on the red team, same applies for all.
if #game.Teams:WaitForChild("Red"):GetPlayers() >= 1 and #greenTeam:GetPlayers() == 0 and #blueTeam:GetPlayers() == 0 and #yellowTeam:GetPlayers() == 0 and yellowTeam.EggBroken.Value == true and blueTeam.EggBroken.Value == true and greenTeam.EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(plr)
end
end
if plr.Team == greenTeam then -- player is on the red team, same applies for all.
if #greenTeam:GetPlayers() >= 1 and #game.Teams:WaitForChild("Red"):GetPlayers() == 0 and #blueTeam:GetPlayers() == 0 and #yellowTeam:GetPlayers() == 0 and blueTeam.EggBroken.Value == true and yellowTeam.EggBroken.Value == true and game.Teams:WaitForChild("Red").EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(plr)
end
end
if plr.Team == blueTeam then -- player is on the red team, same applies for all.
if #blueTeam:GetPlayers() >= 1 and #game.Teams:WaitForChild("Red"):GetPlayers() == 0 and #greenTeam:GetPlayers() == 0 and #yellowTeam:GetPlayers() == 0 and yellowTeam.EggBroken.Value == true and game.Teams:WaitForChild("Red").EggBroken.Value == true and greenTeam.EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(plr)
end
end
if plr.Team == yellowTeam then -- player is on the red team, same applies for all.
if #yellowTeam:GetPlayers() >= 1 and #greenTeam:GetPlayers() == 0 and #blueTeam:GetPlayers() == 0 and #game.Teams:WaitForChild("Red"):GetPlayers() == 0 and game.Teams:WaitForChild("Red").EggBroken.Value == true and blueTeam.EggBroken.Value == true and greenTeam.EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(plr)
end
end
end)
yellowTeam.EggBroken:GetPropertyChangedSignal("Value"):Connect(function()
task.wait(0.01)
if plr.Team == game.Teams:WaitForChild("Red") then -- player is on the red team, same applies for all.
if #game.Teams:WaitForChild("Red"):GetPlayers() >= 1 and #greenTeam:GetPlayers() == 0 and #blueTeam:GetPlayers() == 0 and #yellowTeam:GetPlayers() == 0 and yellowTeam.EggBroken.Value == true and blueTeam.EggBroken.Value == true and greenTeam.EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(plr)
end
end
if plr.Team == greenTeam then -- player is on the red team, same applies for all.
if #greenTeam:GetPlayers() >= 1 and #game.Teams:WaitForChild("Red"):GetPlayers() == 0 and #blueTeam:GetPlayers() == 0 and #yellowTeam:GetPlayers() == 0 and blueTeam.EggBroken.Value == true and yellowTeam.EggBroken.Value == true and game.Teams:WaitForChild("Red").EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(plr)
end
end
if plr.Team == blueTeam then -- player is on the red team, same applies for all.
if #blueTeam:GetPlayers() >= 1 and #game.Teams:WaitForChild("Red"):GetPlayers() == 0 and #greenTeam:GetPlayers() == 0 and #yellowTeam:GetPlayers() == 0 and yellowTeam.EggBroken.Value == true and game.Teams:WaitForChild("Red").EggBroken.Value == true and greenTeam.EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(plr)
end
end
if plr.Team == yellowTeam then -- player is on the red team, same applies for all.
if #yellowTeam:GetPlayers() >= 1 and #greenTeam:GetPlayers() == 0 and #blueTeam:GetPlayers() == 0 and #game.Teams:WaitForChild("Red"):GetPlayers() == 0 and game.Teams:WaitForChild("Red").EggBroken.Value == true and blueTeam.EggBroken.Value == true and greenTeam.EggBroken.Value == true then
game.ReplicatedStorage.Events.rewardWin:FireClient(plr)
end
end
end)
I also added a die detector as you can see:
script.Parent:WaitForChild("Humanoid").Died:Connect(function()
if game.Teams:FindFirstChild(game:GetService("Players"):GetPlayerFromCharacter(script.Parent).Team.Name).EggBroken.Value == false then
for i, Child in pairs(script.Parent:WaitForChild("Humanoid"):GetChildren()) do
if Child:IsA('ObjectValue') and Child.Value and Child.Value:IsA('Player') then
local Killer = Child.Value
if Killer:FindFirstChild "leaderstats" and Killer.leaderstats:FindFirstChild "Kills" then
game.ReplicatedStorage.DiedRE:FireServer(Killer, Killer.KillEffect.Value)
end
return
end
end
else
game.ReplicatedStorage.Events.RemoveFromTeam:FireServer()
end
end)
Help please?
Are there any errors? Sorry for the long reply, I was sleeping.
I think the problem is the plr, since it will change every time a new player joins.
Do you need to check if the player is in the team? Maybe you can just get the team’s members and fire the win on them using a loop.
Example:
local WinnerTeam
for i,Team in pairs(game.Teams:GetChildren()) do
if Team.Name ~= "Spectators" then -- so spectator team doesn't count
if #Team:GetPlayers() > 0 then
WinnerTeam = Team.Name -- The team that won
end
end
for i,Player in pairs (WinnerTeam:GetPlayers()) do
Event:FireClient(Player)
end
end
end
This is just an example, it might have errors since I just wrote it in mobile.
Oh hey!
Yes, one of them is when destroying a team, it doesn’t get the destroyed team again. If you don’t understand what I mean, I tried it with two people in one server, and I basically broke all the beds and eliminated the player wuth me, they got sent to the spectators team and their team got destroyed. Instead of giving me the win, it game me another error saying that the red team should be in the teams service.
Oh, maybe you shouldn’t destroy the team since we are checking for players.
Or maybe, instead of checking for a team’s players, you could destroy the team then, use
game.Teams.ChildRemoved:Connect(function()) -- Updates each time a team is destroyed
local TeamsLeft = 0
local Winner
for i, Team in pairs(game.Teams:GetChildren()) do
if Team:IsA("Team") and Team.Name ~= "Spectators" then -- checking if the child is a team and isnt spectator team
TeamsLeft += 1
Winner = Team
end
end
if TeamsLeft == 1 then
for i,Player in pairs(Winner:GetPlayers()) do
RemoteEvent:FireClient(Player) -- Change RemoteEvent to the event you want to fire
end
end
end)
This code replaces the whole team checking thing, by checking for destroyed teams instead of the team’s players. You will need to destroy them for this to work.
This code might need some changes.
I might have another idea.
I think we shouldn’t destroy the team, and just set the dead player’s team to spectators, and using the player removed event too. That will be much easier.
You can try that, if it doesn’t work, try the code I wrote above.
Alright, I’m writing your script right now, Should I remplace everything with it?
For now, maybe you should just disable the old script and make a new one, so if this doesn’t work you can go back to the old one.
In that case, you can. But you will still need a script for removing the teams when its empty.
I already did, it is the same from the die detector local script.
game.ReplicatedStorage.Events.RemoveFromTeam.OnServerEvent:Connect(function(player)
game:GetService("Teams"):WaitForChild(player.Team.Name):Destroy()
player.Team = game:GetService("Teams"):WaitForChild("Spectators")
end)
Alright, your script didn’t work… With no errors. Even though it removes the team, nothing happens.
I think we should use the other script you posted here. I’ll let you know.
You could try printing around the script to see where it’s not working, but you can use the other one. Disable the team removing script for that one to work.
Okay, so…
All the scripts didn’t work, so I guess I’ll use my old script for now. I’m going to make some changes so it triggers when:
- The bed value is broken.
- A team is destroyed.
- A player got removed from a team.
I’m sorry about that, I hope you manage to make your script work. Tell me if I can help with anything else.