Team Change then Respawn Player

Hey, I’m trying to make a team changer GUI that changes the players team then respawns them. But the respawn part isn’t working; this is the script I’m using right now.

local Player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()

Player.TeamColor = BrickColor.new(“Steel blue”)

Player:LoadCharacter()

end)

–I’m new to scripting and appreciate the help.

2 Likes

I think Player:LoadCharacter() only works in server scripts. You will have to either use a remote or set their health to 0 manually(Player.Character.Humanoid.Health = 0)

1 Like

You must fire a remote event to a server script. From there, you can respawn the player using Player:LoadCharacter()

1 Like

You can’t change a player’s team from a local script as it won’t reflect to the entire server. To do this you’ll need a “RemoteEvent” instance which allows for the local script (which handles the Gui button click) to communicate with the server script (which will handle changing the player’s team).

--LOCAL SCRIPT--
local Storage = game:GetService("ReplicatedStorage")
local RE = Storage:WaitForChild("RemoteEvent")

script.Parent.MouseButton1Click:Connect(function()
	RE:FireServer()
end)
--SERVER SCRIPT--
local Storage = game:GetService("ReplicatedStorage")
local RE = Storage:WaitForChild("RemoteEvent")

RE.OnServerEvent:Connect(function(Player)
	Player.TeamColor = BrickColor.new("Steel blue")
	Player:LoadCharacter()
end)

Organisation:
image

2 Likes