)How would I make my team change gui select buttons disappear whenever you select your team?

I have this team change gui, where you press on a team button and then a select button comes up, like this:


But when you select your team I want the select button to go away, but it just stays there for the whole gaming session. Ive tried searching everywhere for an answer. Here is the script:

local Camera = game.Workspace.CurrentCamera
local player = script.Parent.Parent.Parent.Parent.Parent
local TeamChoose = script.Parent.Parent
local Player = game.Players.LocalPlayer


script.Parent.MouseButton1Click:Connect(function()
	script.Parent.TextButton.Visible = not script.Parent.TextButton.Visible
end)


	
script.Parent.TextButton.MouseButton1Click:Connect(function()
	player.Team = game.Teams.Dark
	TeamChoose:TweenPosition(UDim2.new(0.25, -0,-1, -0),"Out","Quint",1,true)
	player.Character.Humanoid.Health = 0
end)

NOTE: There are two of these one for each team.

1 Like

I think it’s not working because you’re trying to change the team on the client. Instead, have the client fire a RemoteEvent that tells the server the name of the team it wants to join.

Here’s a quick solution to your issue:

-- server
local Teams = game:GetService("Teams")

local TeamChangeEvent = Instance.new("RemoteEvent", game:GetService("ReplicatedStorage"))
TeamChangeEvent.Name = "TeamChange"

TeamChangeEvent.OnServerEvent:Conenct(function(Player, Team)
    if Teams:FindFirstChild(Team) then
         Player.Team = Teams[Team]
         wait(1)
         Player:LoadCharacter() -- respawns the player's character instead of killing it
    end
end)
-- client
local TeamChangeEvent = game:GetService("ReplicatedStorage"):WaitForChild("TeamChange")
local TeamChoose = script.Parent.Parent
local Player = game:GetService("Players").LocalPlayer


script.Parent.MouseButton1Click:Connect(function()
    script.Parent.TextButton.Visible = not script.Parent.TextButton.Visible
end)

script.Parent.TextButton.MouseButton1Click:Connect(function()
    TeamChangeEvent:FireServer("Dark")
    TeamChoose:TweenPosition(UDim2.new(0.25, -0,-1, -0),"Out","Quint",1,true)
end)

Are you sure that would make the select gui go away whenever you select a team?
EDIT:
I already have a remote event, but this script may help.
–Handle RemoteEvent for TeamChange

game.ReplicatedStorage.ChangeTeam.OnServerEvent:Connect(function(player,teamColor)
player.TeamColor = teamColor
player:LoadCharacter()
end)

Yes, I kept your Tween statement.

script.Parent.TextButton.MouseButton1Click:Connect(function()
    TeamChangeEvent:FireServer("Dark")
    TeamChoose:TweenPosition(UDim2.new(0.25, -0,-1, -0),"Out","Quint",1,true) -- tweens the TeamChoose
end)