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

How can I make an on death change team script?

Asked by 10 years ago

Is there something wrong in this?

h = script.Parent:GetChildren("Humanoid")

if h.Health = 0 then
script.Parent.Parent.TeamColor = BrickColor.new("White")
end

3 answers

Log in to vote
-1
Answered by 10 years ago
h = script.Parent:FindFirstChild("Humanoid") --First error. You need to search for a specific name, so use FindFirstChild.
h.Died:connect(function () --The if function will only run once. This runs every time your character dies.
    game.Players:FindFirstChild(script.Parent.Name).TeamColor = BrickColor.new("White") --You tried to access the workspace.
end)

I'm Aurum, and you're welcome.

0
Thanks chill22518 145 — 10y
Ad
Log in to vote
1
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
10 years ago

The problem with that is that you're using an if statement without some sort of loop. This will onlt check once, and that is when the script is first processed. And there is no cjhance of the player being dead yet so what you have to do is wait for them to die by repeatedly checking or using the Died event. I prefer the latter.

h = script.Parent:FindFirstChild("Humanoid")

h.Died:connect(function()
script.Parent.Parent.TeamColor = BrickColor.new("White")
end)

Also, you may want to check your methods of accessing the player and their humanoid because that doesn't look right. And 'GetChildren' should be replaced witrh FindFirstChild if it's not already incorrect.

-Goulstem

Log in to vote
0
Answered by 10 years ago

You can do this with the Died event The died event runs when a player dies for example

game:GetService('Players').PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(character)
        character:WaitForChild("Humanoid").Died:connect(function()
            print(player.Name .. " has died!")
        end)
    end)
end)

Prints the players name that died. For example.If i died the output would print Iluvmaths1123 has died! Now here is the script

game:GetService('Players').PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(character)
        character:WaitForChild("Humanoid").Died:connect(function()
            script.Parent.Parent.TeamColor = "White"
        end)
    end)
end)

Answer this question