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

How do I make my players change team when they are killed by someone from the enemy team or an NPC?

Asked by 9 years ago

I'm making a game where there are 2 teams, Survivors and Zombies, I want all players to be on the Survivors team to start with, and as npc's kill them, they join the Zombie team (work with the npc's).

My idea was to make a script that would work universally with every player but my problem is I do not know how to reference to the players humanoid as I do not know how to do it without using an exact username. I've looked at 30 tuts today to no avail and really need someone to show me what to do, I'd even let someone connect to my pc via team viewer. I'm keen about learning however I am really stuck. also, I wanted to make a score board where every time someone dies, the remaining survivors gain 1 point (like cod infection). Any help is appreciated, this is making me frustrated that I can't get it.

if game.Workspace.Player.Humanoid.Died and game.Players.

end

^^^ Your probably laughing at me rn but I've tried so many different things :(

1 answer

Log in to vote
-2
Answered by 9 years ago

In a server script

game.Players.PlayerAdded:connect(function(Player) 
    Player.CharacterAdded:connect(function(Character)
        local Humanoid = Character:WaitForChild("Humanoid") -- waits until Humanoid it finds Humanoid
        Humanoid.Died:connect(function(Died) 
            local creator = Humanoid:FindFirstChild("creator") -- in a roblox already made sword script when the sword or whatever else it is hits the character it sets a StringValue in the humanoid
            if creator ~= nil then
                local AP = creato -- AP means AttackingPlayer
                TeamColor = AP.TeamColor
                Player.TeamColor = TeamColor -- set players team color to opponents 
            end
        end)
    end)
end)

Heres how the script works 1. Gets Player on startup 2. Gets Character after it gets Player 3. Gets humanoid after it gets Character 4. Makes a Died event for Humanoid 5. When Player dies it sets the Players TeamColor to the opponents TeamColor

0
Thankyou so much! I just have one question, if the script changes the player to its attackers team, wont it change my zombie team players to survivors? D1G1LANT3 -2 — 9y
0
Why would you just write the script for him? He needs to know, If you just give him the answers he's not going to learn. EzraNehemiah_TF2 3552 — 9y
Ad

Answer this question