Help With Team Change

Hello, so I’m working on a main menu. I’m not sure why it’s not changing the players team. I have a gui in startgui with a local script that does everything. Here is what it says.

function hitPlay()
if selectedTeam == “N/A” then
mainMenuUI.SelectTeam.Visible = true
wait(5)
mainMenuUI.SelectTeam.Visible = false
elseif selectedTeam ~= “N/A” then
guiEvents.TeamChange:FireServer(plr, selectedTeam)
guiEvents.ReloadChar:FireServer(plr)
script.Parent.Enabled = false
end
end

The selectedTeam has the teams brick color that the player selected in the menu. It works but when I tried to change the players team from there, it didn’t run through the server so it only changed it on the client. I’m then made a script in server script service.
I have a remove event in replicated storage that the local script fires when the player hits play. I’m not sure how to transfer data though. I don’t know how to transfer what team the player selected in the gui.
Here is what the code in server script server is.

guiEvents.TeamChange.OnServerEvent:Connect(function(plr, selectedTeam)
plr.TeamColor = selectedTeam
end)

function hitPlay()
if selectedTeam == BrickColor.new(0.9,0.8,0.1) ----- team color here then
mainMenuUI.SelectTeam.Visible = false
wait(5)
mainMenuUI.SelectTeam.Visible = true
elseif selectedTeam ~= BrickColor.new(0,0,0) ----- team color here then
guiEvents.TeamChange:FireServer(plr, selectedTeam)
guiEvents.ReloadChar:FireServer(plr)
script.Parent.Enabled = false
end
end

you said selectedTeam is brick color so brick color cant be a string “N/A”

When the player clicks the team, it changed the selectedTeam value.
image

idont get i ineed more info tho can you show me more about your script

– Corey, Site-02.

– Main Menu Handler

– Services & Variables

local ms = game:GetService(“MarketplaceService”)

local repStor = game:GetService(“ReplicatedStorage”)

local guiEvents = repStor.GUIs

local plr = game.Players.LocalPlayer

local selectedTeam = “N/A”

local mainMenuUI = script.Parent.Holder

local buttons = script.Parent.Holder.Buttons

local menus = script.Parent.Holder.Menus

local playButton = buttons:FindFirstChild(“1Play”)

local teamButton = buttons:FindFirstChild(“2Team”)

local settingsButton = buttons:FindFirstChild(“3Settings”)

local storeButton = buttons:FindFirstChild(“4Store”)

local creditsButton = buttons:FindFirstChild(“5Credits”)

local teamChangeMenu = menus.TeamChange

local teams = teamChangeMenu.Teams

local teamLabel = teamChangeMenu.currentTeam

local storeMenu = menus.Store

local gamepassInfo = storeMenu.GamepassInfo

local settingsMenu = menus.Settings

local creditsMenu = menus.Credits

– Main Code

– Add play button.

script.Parent.Enabled = true

function hitPlay()

if selectedTeam == “N/A” then

mainMenuUI.SelectTeam.Visible = true

wait(5)

mainMenuUI.SelectTeam.Visible = false

elseif selectedTeam ~= “N/A” then

guiEvents.TeamChange:FireServer(plr, selectedTeam)

guiEvents.ReloadChar:FireServer(plr)

script.Parent.Enabled = false

end

end

function menuTeams()

closeMenus()

teamChangeMenu.Visible = true

if plr.leaderstats.XP.Value >= 50 then

teams.SD.Locked.Visible = false

teams.SD.Active = true

end

end

function teamCD()

selectedTeam = BrickColor.new(“Deep orange”)

updateTeamLabel()

end

function teamSD()

selectedTeam = BrickColor.new(“Dark stone grey”)

updateTeamLabel()

end

function closeMenus()

teamChangeMenu.Visible = false

storeMenu.Visible = false

settingsMenu.Visible = false

creditsMenu.Visible = false

end

function menuCredits()

closeMenus()

creditsMenu.Visible = true

end

function menuSettings()

closeMenus()

settingsMenu.Visible = true

end

function menuStore()

closeMenus()

storeMenu.Visible = true

end

function infoDoubleXP()

gamepassInfo.DoubleXP.Visible = true

end

function closeDoubleXP()

gamepassInfo.DoubleXP.Visible = false

end

function buyDoubleXP()

ms:PromptGamePassPurchase(plr, 23819722)

end

function updateTeamLabel()

if selectedTeam == BrickColor.new(“Deep orange”) then

teamLabel.Text = “Current Team Selected: Class-D”

elseif selectedTeam == BrickColor.new(“Dark stone grey”) then

teamLabel.Text = “Current Team Selected: Security Department”

end

end

– Triggers

playButton.MouseButton1Click:Connect(hitPlay)

teams.SD.MouseButton1Click:Connect(teamSD)

teams.CD.MouseButton1Click:Connect(teamCD)

teamButton.MouseButton1Click:Connect(menuTeams)

settingsButton.MouseButton1Click:Connect(menuSettings)

creditsButton.MouseButton1Click:Connect(menuCredits)

storeButton.MouseButton1Click:Connect(menuStore)

storeMenu.DoubleXP.Purchase.MouseButton1Click:Connect(infoDoubleXP)

gamepassInfo.DoubleXP.Back.MouseButton1Click:Connect(closeDoubleXP)

gamepassInfo.DoubleXP.Purchase.MouseButton1Click:Connect(buyDoubleXP)

server script service script.
– Corey, Site-02.

– Main Menu Server Handler

– Services & Variables

local repStor = game:GetService(“ReplicatedStorage”)

local guiEvents = repStor.GUIs

– Main Code

guiEvents.ReloadChar.OnServerEvent:Connect(function(plr)

plr:LoadCharacter()

end)

guiEvents.TeamChange.OnServerEvent:Connect(function(plr, selectedTeam)

plr.TeamColor = selectedTeam

end)

use local selectedTeam = plr.TeamColor or start teamCD() befor hitPlay()

if that did not work print selected team and tell me what it print

guiEvents.TeamChange.OnServerEvent:Connect(function(plr, selectedTeam).
print(selectedTeam)
plr.TeamColor = selectedTeam
end)

Oh, didn’t even think about printing. I’ll do that.

It printed my username. I also saw that there was a error from the same script.

The error is coming from this line.image

what the print says befor the error

The print says my roblox username.

look selected team it is string you have to make it break color in script remove this local selectedTeam = “N/A” and replace it with the script igave you local selectedTeam = plr.TeamColor just try

It doesn’t work. It does the same thing as last time.

and do this after it replace hit play() with

function hitPlay()
if selectedTeam == BrickColor.new("Dark stone grey") then ----- team color here then
mainMenuUI.SelectTeam.Visible = false
wait(5)
mainMenuUI.SelectTeam.Visible = true
elseif selectedTeam ~= BrickColor.new("Deep orange") then  ----- team color here then
guiEvents.TeamChange:FireServer(plr, selectedTeam)
guiEvents.ReloadChar:FireServer(plr)
script.Parent.Enabled = false
end
end

The play button doesn’t even do anything now.

re copy and past the script and change the color inside BrickColor.new(“Deep orange”) to match what you want teams color be this is it

1 Like