Help With a Death Message Script

Hello there! I’m having a small issue with this script. It’s supposed to pick a random message out of a table, and display it to the player when they die. The issue is, it only runs once. If the player dies one time, everything appears to work fine. If they die a second time, nothing happens. No errors either. It only works one time, then completely stops. Some help on how to fix this would be very appreciated :slight_smile: Note: “script.Parent” is referring a TextLabel, of which this script is a child of.

local deathMessages = {
	"OOF",
	"Wow, you suck.",
	"Really..",
	"Ouch",
	"Goodbye",
	"That looked painful.",
	"Glad i'm not you.",
	"Zoinks",
	"Mistakes were made..",
	"You died.",
	"Good job, buddy."
}

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()

local humanoid = char:WaitForChild("Humanoid")
	
humanoid.Died:Connect(function()	
	local random = math.random(1, #deathMessages)
	
	script.Parent.Text = deathMessages[random]
	script.Parent.Visible = true
		
	wait(6)
		
	script.Parent.Visible = false
end)

Thank you!

Edit: This was solved by @Avallachi. if anyone is curious what this is being used for, check it out here. (yes, this a shameless self-promo lol) Escape The VOID [In-Dev Demo] - Roblox

1 Like

Try to use:
if humanoid.Health == 0 then end

I already did. I also used :GetPropertyChangedSignal() along with humanoid.Health == 0. Same thing happened.

1 Like

Try to use player.CharacterAdded:Wait() only
also sorry I type the wrong word

if it had anything to do with the character, the script wouldn’t work entirely, because it’s checking to see if the Humanoid died, which is part of the character. As you already read in the original post, It only shows the message once, and then never shows it again. No errors. Just doesn’t show again, with no explanation. So if it shows once, that means it found the character successfully. I’m completely stumped.

1 Like

Try removing the CharacterAdded:Wait()

This is due to your code is made only to check for a character, and run once. Is the ResetOnSpawn property of the ScreenGui set to true?

1 Like

No. Removing that would throw an error. player.Character has a 99% chance of failing. The character never loads before the script runs.

1 Like

Oh! I know, when the character dies, then it’s a new character generated for that player, so that died character’s parent is nil, so removed the line. Player.Character, only put Player.CharacterAdded:Wait()

No, it wasn’t, but now it is, and everything works fine! Thanks for the help. And also thanks @55167233gf and @XXgamerisaliveXx!

2 Likes

Removing Player.Character will not make a difference.

I had a game, the tool didn’t work after the player died. So, that’s what I did and I got help from the DevForum and fixed it