Death message script not working

Hi,

I’m trying to make a death message but this script isn’t working

game:GetService('Players').PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
	    character:WaitForChild("Humanoid").Died:Connect(function()
		    script.Parnet.Visible = true
		    wait(5)
		    script.Parent.BackgroundTransparency = .1
		    wait(.1)
		    script.Parent.BackgroundTransparency = .2
		    wait(.1)
		    script.Parent.BackgroundTransparency = .3
		    wait(.1)
		    script.Parent.BackgroundTransparency = .4
		    wait(.1)
		    script.Parent.BackgroundTransparency = .5
		    wait(.1)
		    script.Parent.BackgroundTransparency = .6
		    wait(.1)
		    script.Parent.BackgroundTransparency = .7
		    wait(.1)
		    script.Parent.BackgroundTransparency = .8
		    wait(.1)
		    script.Parent.BackgroundTransparency = .9
		    wait(.1)
		    script.Parent.BackgroundTransparency = 1
		    script.Parent.Visible = false
	    end)
    end)
end)

I hope you can help me!

From,
File

1 Like

“Parnet” should be “Parent”

Hope this helps!

I took away the sound statement. Sorry! I accidentally put that in there.

Try this:

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        character:WaitForChild("Humanoid").Died:Connect(function()
            wait(5)
            for i = 0, 1, 0.1 do
                script.Parent.BackgroundTransparency = i
                wait(.1)
            end
        end)
    end)
end)

Plus, you don’t need to say script.Parent.Visible = false at the end because when the background transparency reaches one, it alrdy invisible/

okay I will try this out! Also I will keep that in mind.

it still doesn’t work for some reason.

If this is on a Server Script, do please change it to a LocalScript and try this:

You’re able to easily access the Local Player by using game.Players.LocalPlayer

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Thingy = script.Parent

Humanoid.Died:Connect(function()
    Thingy.Visible = true
    wait(5)
    for Loop = 1, 10 do
        Thingy.BackgroundTransparency += .1
        wait(.1)
    end
    Thingy.Visible = false
end)

Here as well too. “Parnet” instead of “Parent”

As far as i can remember usually died event can also be fired when player is spawning so instead of using the Died event i would recommend to try and use Humanoid.Health = 0 instead

How would I solve it


Changes:

  • Use TweenService to reduce code
  • Fix spelling mistakes *i.e Parnet to Parent (script.Parnet.Visible = true)
  • Using Local Script inside the Death Message Frame

Code:

local tweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(1) -- Set the number to how long you want the fade to take

local plr = game.Players.LocalPlayer
local char = plr.Character
local humanoid = char:WaitForChild("Humanoid")

local deathFrame = script.Parent -- Getting death frame

deathFrame.Visible = false

humanoid.Died:Connect(function()
	deathFrame.Visible = true
	local tween = tweenService:Create(deathFrame, tweenInfo, {BackgroundTransparency = 0})
	tween:Play()
	
	wait(1.5) -- Tween length + Interval beteen the fade in and the disapering
	
	deathFrame.Visible = false -- Resetting frame
	deathFrame.BackgroundTransparency = 1
end)

I hope this was useful