Hello! I’ve been trying to make a script, which checks how many players are currently in a specific team, and then arrange placements (if there are 5 players on the team and somebody dies, put the player to the 5th placement).
The problem is that it works before I’d want it to. It works the first time they get teamed and respawned. However, it should work only after they have been respawned to the Alive team already. (If they are on the Alive team, got respawned and then died on the Alive team)
local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
local RS = game:GetService("ReplicatedStorage")
local EndGameEvent = RS:WaitForChild("EndGame")
local SS = game:GetService("ServerStorage")
local PlacementsFolder = SS:WaitForChild("Placements")
local FirstValue = PlacementsFolder:WaitForChild("1st")
local SecondValue = PlacementsFolder:WaitForChild("2nd")
local ThirdValue = PlacementsFolder:WaitForChild("3rd")
local FourthValue = PlacementsFolder:WaitForChild("4th")
local FifthValue = PlacementsFolder:WaitForChild("5th")
Players.PlayerAdded:Connect(function(Player)
Player.CharacterRemoving:Connect(function()
if Player.Team == Teams.Alive then
local TeamCount = Teams.Alive:GetPlayers()
if #TeamCount == 5 then
FifthValue.Value = Player.Name
elseif #TeamCount == 4 then
FourthValue.Value = Player.Name
elseif #TeamCount == 3 then
ThirdValue.Value = Player.Name
elseif #TeamCount == 2 then
SecondValue.Value = Player.Name
elseif #TeamCount == 1 then
print("YES!")
FirstValue.Value = Player.Name
end
print("5: "..FifthValue.Value)
print("4: "..FourthValue.Value)
print("3: "..ThirdValue.Value)
print("2: "..SecondValue.Value)
print("1: "..FirstValue.Value)
end
end)
end)