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

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

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)

1 comment

0

CharacterAdded event is fire when the Character spawn or respawn. https://developer.roblox.com/api-reference/event/Player/CharacterAdded

1 answer

✓ Accepted answer

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)

2 comments

0

Works! Thank you!

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.

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