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

How would you wait until a humanoid dies and finishes respawning?

Asked by
Talveka 31
4 years ago
Edited 4 years ago

I have a simple coloring system that changes the player's color once they respawn. However, I'd need to wait until they finish respawning and then apply the colors, else they'll revert to normal.

I've already tried this, however it doesnt seem to be working (line 4);

repeat wait() until char.Humanoid.Health == 100

Here's my full script;

game.Players.PlayerAdded:Connect(function(plr)
    local char = plr.Character or plr.CharacterAdded:Wait()
    char.Humanoid.Died:Connect(function()
        repeat wait() until char.Humanoid.Health == 100
        local onecolor1 = char.Wing1
        local onecolor2 = char.Wing2
        -- wing colors above
        local twocolor1 = char.Body
        local twocolor2 = char.Antenna1
        local twocolor3 = char.Antenna2
        -- body colors above
        local randomcolor1 = BrickColor.Random()

        onecolor1.BrickColor = randomcolor1
        onecolor2.BrickColor = randomcolor1
        -- coloring the wings
        local randomcolor2 = BrickColor.Random()

        twocolor1.BrickColor = randomcolor2
        twocolor2.BrickColor = randomcolor2
        twocolor3.BrickColor = randomcolor2
        -- coloring the body
    end)
end)
0
CharacterAdded event is fire when the Character spawn or respawn. https://developer.roblox.com/api-reference/event/Player/CharacterAdded Block_manvn 395 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

Try using a CharacterAdded function instead of the repeat.

game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function()
        local char = plr.Character or plr.CharacterAdded:Wait()
        local onecolor1 = char.Wing1
        local onecolor2 = char.Wing2
        -- wing colors above
        local twocolor1 = char.Body
        local twocolor2 = char.Antenna1
        local twocolor3 = char.Antenna2
        -- body colors above
        local randomcolor1 = BrickColor.Random()

        onecolor1.BrickColor = randomcolor1
        onecolor2.BrickColor = randomcolor1
        -- coloring the wings
        local randomcolor2 = BrickColor.Random()

         twocolor1.BrickColor = randomcolor2
        twocolor2.BrickColor = randomcolor2
        twocolor3.BrickColor = randomcolor2
        -- coloring the body
    end)
end)
0
Works! Thank you! Talveka 31 — 4y
1
The CharacterAdded signal supplies the Character being added through a parameter. There is no need to define it again, or yield the signal within the scope. Ziffixture 6913 — 4y
Ad

Answer this question