Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I change teams after death?

Asked by 5 years ago

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
0
I have really low Rep because I had to deactivate my account twice and nobody gives an Answer but only give Comments zboi082007 270 — 5y
0
Do you already have the team service added? benben3963 6 — 5y
0
Obviously zboi082007 270 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago
Edited by User#24403 5 years ago

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)

0
thx xxaxxaz 42 — 2y
Ad
Log in to vote
0
Answered by 5 years ago

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.

0
(This one runs on the server instead of client.) benben3963 6 — 5y

Answer this question