My Team Assignment Script Isn't Working

  1. What do you want to achieve? I want to make team menu that when the join button is pressed they will be assigned to that team

  2. What is the issue? My script is simply not working, and there are no errors.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub? Yes, I did look for other solutions on the devhub, to which I found nothing that helped me with my situation. I’ve also tried looking for help in one of the roblox developer Discord Servers I was in. To which they didn’t know how to help me and told me to go here instead.

My script:

local teams = game.Teams
local devTeam = teams.Developer
local selecting = teams["Selecting Team"]
local joinButton = script.Parent
local player = game.Players.LocalPlayer

repeat wait() until game:IsLoaded(true)

joinButton.MouseButton1Up:Connect(function()
	game:GetService('Teams'):GetTeams()
	if player.Team == selecting then
		player.Team = devTeam
		end
end)

if player.Team == devTeam then
	joinButton.Visible = false else
	joinButton.Visible = true
end

(Note: I really don’t know what I’m doing I’ve never used a table with teams before)

Is the ‘selecting’ team the default team?
If not you can team them automatically when they join to the ‘selecting’ team.

You’re running the script in a LocalScript (on the client side), try running it in a server Script instead.

That won’t work, game.Players.LocalPlayer can’t be used in a Server Script

local teams = game.Teams
local devTeam = teams.Developer
local selecting = teams["Selecting Team"]
local joinButton = script.Parent
local player = game.Players.LocalPlayer

repeat wait() until game:IsLoaded() == true

joinButton.MouseButton1Up:Connect(function()
	game:GetService('Teams'):GetTeams()
	if player.Team == selecting then
		player.Team = devTeam
	end
end)

if player.Team == devTeam then
	joinButton.Visible = false else
	joinButton.Visible = true
end

My script is inside the join button though…

Nevermind I just fixed it, all I had to do was move it into the function and it works fine now.

local ts = game:GetService('TweenService')
local teams = game.Teams
local devTeam = teams.Developer
local selecting = teams["Selecting Team"]
local joinButton = script.Parent
local player = game.Players.LocalPlayer
local cam = game.Workspace.CurrentCamera

repeat wait() until game:IsLoaded(true)

joinButton.MouseButton1Up:Connect(function()
	game:GetService('Teams'):GetTeams()
	if player.Team == selecting then
		player.Team = devTeam
		
		if player.Team == devTeam then
			joinButton.Visible = false else
			joinButton.Visible = true
		end
	end
end)

Well, of course you have to apply a few changes to work server-sided.