If the intruders team is full, you don’t have it setting the team. You also have no way to insure that the intruders team has someone in it. Here is a script that includes both of those, and also a way to detect if the intruder leaves the game:
local intruder = nil
game.Players.PlayerAdded:Connect(function(Player)
local Teams = game:GetService("Teams"):GetTeams()
local RandomTeam = Teams[math.random(1,#Teams)]
if RandomTeam.Name == "Intruders" then
if #RandomTeam:GetPlayers() < 1 then
Player.Team = RandomTeam --Intruder
intruder = Player -- sets intruder
local PointLight = Instance.new("PointLight")
PointLight.Enabled = true
PointLight.Color = Color3.fromRGB(80, 0, 0)
PointLight.Brightness = 0.6
PointLight.Shadows = true
PointLight.Range = 6
wait(1)
PointLight.Parent = Player.Character.Torso
else
Player.Team = game:GetService("Teams").Homeowners -- you may need to edit to be the correct name
end
else
Player.Team = RandomTeam --Home Owner
local PointLight = Instance.new("PointLight")
PointLight.Enabled = true
PointLight.Color = Color3.fromRGB(255, 255, 255)
PointLight.Brightness = 0.2
PointLight.Shadows = true
PointLight.Range = 4
wait(1)
PointLight.Parent = Player.Character.Torso
end
if not intruder then
Player.Team = game:GetService("Teams").Intruders
intruder = Player
end
end)
-- makes it so if the intruder leaves, the intruder is set back to nil. Note that this will not set a new intruder
game.Players.PlayerRemoving:Connect(function(Player)
if Player == intruder then
intruder = nil
end
end)
Though with how you have it set up, the first person who joins will always be the intruder. The best way to fix this is instead of when a player is added it does this, it does it at the start of the round. If you need help doing that let me know.