"Team is not a valid member of Team 'Teams.Queued'"

Hi! I am attempting to script a GUI that changes a player’s team when they press a button. Everything is pathed correctly and I am using RemoteEvents to ensure that changes from the LocalScript are applied to the server. The local script is as follows:

local player = game:GetService("Players").LocalPlayer
local teams = game:GetService("Teams")
local button = script.Parent
local event = game:GetService("ReplicatedStorage").TeamChange

function teamChange()
	local team = player.Team
	if team.Name == "Queued" then
		event:FireServer(teams.NotPlaying,player)
	elseif team.Name == "NotPlaying" then
		event:FireServer(teams.Queued,player)
	end
end

button.MouseButton1Click:Connect(teamChange)

The server script is as follows.

local players = game:GetService("Players")
local teams = game:GetService("Teams")
local event = game:GetService("ReplicatedStorage").TeamChange

event.OnServerEvent:Connect(function(team,player)
	print("heard, "..tostring(player).." "..tostring(team))
	player.Team = team
end)

Everything runs fine until it tries to change the team. When it gets to line 7, it throws an error that reads Team is not a valid member of Team "Teams.Queued". Any advice on why this could be? “Queued” and “NotPlaying” are valid teams.

in the OnServerEvent event, the first param is always the player. so switch the positions of the team param and the player param

local players = game:GetService("Players")
local teams = game:GetService("Teams")
local event = game:GetService("ReplicatedStorage").TeamChange

event.OnServerEvent:Connect(function(player, team)
	print("heard, "..tostring(player).." "..tostring(team))
	player.Team = team
end)
1 Like

Thanks! Didn’t work the first time I tried it, guess it was a fluke. Works like a charm now.

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