I am currently build a sort of "raid fort", teams as you could guess plays a major role matchmaking. So I decided to make GUI buttons off to the side of the screen that by clicking them allows you to switch to either team. I have one issue though, despite switching the player to the other team it confines them to the lobby spawn even when the player is killed and spawned.
https://imgur.com/a/959zKHM https://imgur.com/a/MCJwvQ3
I first thought that the spawns of red and blue team might be the problem but, after checking, there didn't seem to be any problems. Here is the two local scripts that are inside of both team changing buttons as well as the explorer view of the starter GUI.
function onButtonClicked() script.Parent.Parent.Parent.Parent.Parent.Character.Humanoid.Health = 0 end script.Parent.MouseButton1Click:connect(onButtonClicked)
function Click(mouse) script.Parent.Parent.Parent.Parent.Parent.TeamColor = BrickColor.new("Bright red") end script.Parent.MouseButton1Down:connect(Click)
https://imgur.com/a/pVad3L3
It's essentially the same for both the red and blue buttons, except the blue button is set for the color "Bright blue" instead of "Bright red"
NOTE:
This does not need to be a server-side (local) script. It can just be a client-side (plain, non-local, non-module, regular, "Script")
local Player = script.Parent.Parent.Parent.Parent.Parent -- USE THESE! function onButtonClicked() Player.TeamColor = BrickColor.new(--[["Bright red" or "Bright blue"--]]) Player:LoadCharacter() -- instead of killing the player, just load a completely new character AFTER the team change. end script.Parent.MouseButton1Click:connect(onButtonClicked) -- Why not combine into ONE script?
Then, in the Bright Red teams' spawn:
script.Parent.Neutral = false
script.Parent.TeamColor --[[ or Team, im in scripting Helpers --]] = BrickColor.new("Bright Red")
Same thing with the Bright Blue's team.
script.Parent.Neutral = false
script.Parent.TeamColor --[[ or Team, im in scripting Helpers --]] = BrickColor.new("Bright Blue")