I need help with scripting respawn when players changes team

Hello,
I need some help with my script

It changes the player from the team when they click the button, but I want it to kill the players after they changed from the team. I just need a simple solution since I don’t know how to even start on it.

I PASTED CODE IN REPLIES

Here’s what I got:

I know how to help, but do you mind pasting the code into the post instead rather than showing a picture of it?

3 Likes

You could set the player’s health into 0 or use LoadCharacter() which will respawn him.

3 Likes

Maybe add something in the script like

script.Parent.Parent.Parent.Parent:LoadCharacter()

or

script.Parent.Parent.Parent.Parent.Character:BreakJoints()

local teams = game:GetService(“Teams”)

local teamnum = 0

local teambutton = script.Parent.TeamButton

for index, child in pairs(teams:GetChildren()) do

local newbutton = teambutton:Clone()

newbutton.Parent = script.Parent

newbutton.Text = child.Name

newbutton.BackgroundColor = child.TeamColor

newbutton.Position = UDim2.new( 0, 0, 0, (teamnum * 50) )

wait()

teamnum = teamnum + 1

newbutton.MouseButton1Click:Connect(function()

script.Parent.Parent.Parent.Parent.Team = child

end)

end

1 Like
local Teams = game:GetService("Teams")
local TeamNum = 0
local TeamButton =  script.Parent.TeamButton

for index,child in pairs(Teams:GetChildren()) do
	local NewButton = TeamButton:Clone()
	NewButton.Parent = script.Parent
	NewButton.Name = child.Name
	NewButton.BackroundColor = child.TeamColor
	NewButton.Position = UDim2.new(0,0,0,(TeamNum * 50))
	
	task.wait()
	
	TeamNum = TeamNum + 1
	NewButton.MouseButton1Click:Connect(function()
		script.Parent.Parent.Parent.Parent.Team = child

		script.Parent.Parent.Parent.Parent:LoadCharacter() 
       --or
		script.Parent.Parent.Parent.Parent.Character.Humanoid.Health = 0
       --or
	    game.Workspace:FindFirstChild(script.Parent.Parent.Parent.Parent.Name).Humanoid.Health = 0
	end)
end
1 Like
local teams = game:GetService(“Teams”)

local teamnum = 0

local teambutton = script.Parent.TeamButton

for index, child in pairs(teams:GetChildren()) do

local newbutton = teambutton:Clone()

newbutton.Parent = script.Parent

newbutton.Text = child.Name

newbutton.BackgroundColor = child.TeamColor

newbutton.Position = UDim2.new( 0, 0, 0, (teamnum * 50) )

wait()

teamnum = teamnum + 1

newbutton.MouseButton1Click:Connect(function()

script.Parent.Parent.Parent.Parent.Team = child
script.Parent.Parent.Parent.Parent.Character:BreakJoints()
end)

end


2 Likes

Correct me if I’m wrong, but I believe using :LoadCharacter() wouldn’t send the player back to spawn, which is why BreakJoints or killing the player is better when changing teams.

2 Likes

It gives an error.
How can I fix this?
image

change it to local teams = game:GetService("Teams")

1 Like