I created two team switch buttons in the form of GUI. It's made so that the GUI is supposed to disappear upon being clicked but it doesn't. It worked, before I added a death upon clicking the button so the player is respawned at the corresponding team spawn. I don't know if the death is the problem, or if it's just some other part of the script.
Two scripts responsible for the team switch:
local rstorage = game:GetService("ReplicatedStorage")
local brightblue = rstorage.Brightblue
local brightred = rstorage.Brightred
local playeradded = rstorage.PlayerAdded
local bluebutton = script.Parent:WaitForChild("Raider")
local redbutton = script.Parent:WaitForChild("Ally")
local gui = script.Parent
playeradded.OnClientEvent:connect(function()
gui.Enabled = true
bluebutton.MouseButton1Click:connect(function()
local splayer = game:GetService("Players")[game:GetService("Players").LocalPlayer.Name]
brightblue:FireServer(splayer)
end)
redbutton.MouseButton1Click:connect(function()
local splayer = game:GetService("Players")[game:GetService("Players").LocalPlayer.Name]
brightred:FireServer(splayer)
end)
end)
local rstorage = game:GetService("ReplicatedStorage")
local brightblue = rstorage.Brightblue
local brightred = rstorage.Brightred
local playeradded = rstorage.PlayerAdded
game.Players.PlayerAdded:connect(function(player)
wait()
playeradded:FireClient(player)
end)
brightblue.OnServerEvent:connect(function(splayer)
splayer.TeamColor = BrickColor.new("Bright blue")
splayer.Character.Humanoid.Health = 0
splayer.leaderstats.Wipeouts.Value = splayer.leaderstats.Wipeouts.Value - 1
end)
brightred.OnServerEvent:connect(function(splayer)
splayer.TeamColor = BrickColor.new("Bright red")
splayer.Character.Humanoid.Health = 0
splayer.leaderstats.Wipeouts.Value = splayer.leaderstats.Wipeouts.Value - 1
end)
