Teams not being switched

The function to change the team runs, yet nothing happens to the player’s team.

local pl = game:GetService('Players')
local teams = game:GetService('Teams')
local spectateTeam = teams.Spectator

pl.PlayerAdded:Connect(function(player)

	local character = player.Character or player.CharacterAdded:Wait()
	
	character.Humanoid.Died:Connect(function()
		player.Team = spectateTeam
	end)
	--This is the function with issues
	game.ReplicatedStorage.LavaEventServer.OnServerEvent:Connect(function(player)
		print("---------Player Function Ran---------")
		game.Players:GetChildren().Team = teams.Player
	end)
	

end)

Is the intent here to make everyone’s team “Player”? If so, you’re going to have to apply this individually through a loop. Here is a quick example.

local Teams = game:GetService("Teams")


game.ReplicatedStorage.LavaEventServer.OnServerEvent:Connect(function(player)
	for i, plr in pairs(game.Players:GetPlayers()) do
		plr.Team = Teams.Player
	end
end)

This works, I just had to change the spectator function to be inside an infinite loop. Thank you so much for helping me out

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.