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.