So I have two buttons that changes the teams of the player, only one time, at the start of the game, and it uses a remote event for activation:
This is located in the ServerScriptService, is a script:
Script
game.ReplicatedStorage.ChangeTeam.OnServerEvent:Connect (function(player, teamColor)
player.TeamColor = teamColor
player:LoadCharacter()
end)
This is located in a GUI, in a Frame, is a localscript:
Localscript
-- Vars
local RemoteEvent = game.ReplicatedStorage.ChangeTeam
local RedColor = "Bright red"
local BlueColor = "Bright blue"
local frame = script.Parent:WaitForChild("teamSelectionFrame")
local tutorialGui = game.Players.LocalPlayer.PlayerGui:WaitForChild("Tutorial")
local menuGui = game.Players.LocalPlayer.PlayerGui:WaitForChild("MENU")
local back = script.Parent.teamSelectionFrame.back
-- Script
frame["Red Bunnies"].MouseButton1Click:Connect(function()
RemoteEvent:FireServer(BrickColor.new(RedColor))
workspace.CurrentCamera.CameraType = "Custom"
tutorialGui.Enabled = true
game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed = 16
end)
frame["Blue Bunnies"].MouseButton1Click:Connect(function()
RemoteEvent:FireServer(BrickColor.new(BlueColor))
workspace.CurrentCamera.CameraType = "Custom"
tutorialGui.Enabled = true
game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed = 16
end)
back.MouseButton1Click:Connect(function()
script.Parent.Enabled = false
menuGui.Enabled = true
end)
It works perfectly but now I want to implement it so the player can’t access the other team if it would make the teams player number unbalanced. I’d appreaciate any suggestion, tip or help for this. If any other detail is needed, please let me know.
Order of the GUI and the buttons: