Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I change teams after death?

I know about the Humanoid.Died function but I don't really understand how I can make them switch teams after they die. I tried using this script and it doesn't work...


local lobby = script.Parent.Lobby
local players = script.Parent.Players

if game.Players.LocalPlayer.Team == players and game.Players.LocalPlayer.Humanoid.Died then
	game.Players.LocalPlayer.Team = lobby
end

3 comments

0

I have really low Rep because I had to deactivate my account twice and nobody gives an Answer but only give Comments

0

Do you already have the team service added?

0

Obviously

2 answers

✓ Accepted answer

Died event


assuming this is a local script

Well, the Died event isn't a function but rather an event, which means the current way you are doing things would error

Because it is an event, it must be formatted like :

humanoid.Died:Connect(function()
	...
end)

rather than what you did.

A couple of other things to note here :

  • Humanoid is a child of the player's character, not of the player itself.

  • Modifying the player's team on a local script, which doesn't work with FE.

  • You placed a local script outside the player/character which means it doesn't run.


Finished Product


With all that said, here is the finished product.

for _,plr in pairs(game.Players:GetPlayers()) do
	local char = plr.Character or plr.CharacterAdded:Wait()
	local hum = char.Humanoid
	hum.Died:Connect(function()
		if plr.Team == game.Teams.Players then
			plr.Team = game.Teams.Lobby
		end
	end)
end

Notice that this shouldn't be on a local script, which means the script doesn't have access to the local player, and since the use of RemoteEvents could be exploited in this case, it is best to handle everything on a server script.

Hopefully this helped!

btw, this isn't a complete script (obviously)

1 comment

0

thx

Here is a quick instructional guild on how to make a user switch teams on death. (Note: Skip to step 3.)

  1. First you need to add TeamService. You can do so by going to the "MODEL" tab on the top of roblox studio and looking to the right for a gear icon with the word "Services" under it. Click it and click "Teams". Then press insert.

  2. Next you need to add a team. You can add one by clicking the plus icon that appears in the explorer over the Teams folder. Then insert a "Team". I will be naming my team "Dead" and making its color "Really red".

  3. Now you need to put a script into "ServerScriptService" and put the following code into it.

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		character:WaitForChild("Humanoid").Died:Connect(function()
			player.Team = game.Teams.Dead
		end)
	end)
end)

Additional Notes: -It may happen that the player spawns in automatically on the Dead team. To fix that add a neutral team.

1 comment

0

(This one runs on the server instead of client.)

This discussion is preserved as it was. New answers, comments, and votes are closed.