#effect on death not working

57 messages · Page 1 of 1 (latest)

warm hare
#

so, i'm trying to make a spooky game that has a glitch effect when you die, i already put the script in the startercharacterscripts but it's still not working.
here's the code:

health = character.humanoid.health
eerror = game.lighting.error -- effect name

function dead()
  health = 0
end

if dead() then
  eerror.enabled = true
end```
i think its an issue with the dead function.
warm hare
#

effect on death not working

knotty garden
#

What the...

warm hare
#

is it bad?

knotty garden
#

Yea... Really bad

#

It doest make any sense

#

First of all, check if character is nil or not (add a print before you declare character)

#

Now, if we know character isnt nil

#

We are gonna use .Died event to run a function when player died

#

lemme check something fast

warm hare
#

ok

knotty garden
#

Aight, I had a little issue, now fixed

#

So, have you checked the character?

warm hare
heavy fulcrumBOT
#

studio** You are now Level 1! **studio

knotty garden
#
char = script.parent
print(char)
warm hare
#

ohh

#

why though?

knotty garden
#

Why what?

warm hare
#

nvm

knotty garden
#

We need to make sure that character isnt nil

#

If is nil, is gonna cause errors

#

Tell me when you checked

#

Hello?

warm hare
#

he is nil

knotty garden
#

Aight

#

Well is the script localized?

warm hare
#

nop

knotty garden
#

where*

#

Sorry

warm hare
#

StarterCharacterScripts

knotty garden
#

Ok

#

Not sure how scripts would load from there

#

So try adding a WaitForChild

warm hare
#

is it waitforchild:char?

knotty garden
#

No

#
local char = script.Parent
repeat 
    char = script.Parent
    wait()
until char ~= nil

I don't know a better way to do it so I come up with this

#

Wait

#

What kind of script is it?

#

Local or server?

warm hare
#

server

knotty garden
#

Ok

#

So now what we got the character, we are gonna use .Died event

warm hare
#

where tho?

#

dead function?

knotty garden
#

2 secs

#

Ok, we got the character so we also have the humanoid

#

We could create a new variable for humanoid

local hum = char:FindFirstChild("Humanoid")
#

And now is time to use the event

hum.Died:Connect(function()
  print("Character died!")
end)
#

Now you just have to add the effect

#

Which I'm not sure what it is and I have to go

#

Sorry

warm hare
#

ok

#

thank you dude

knotty garden
#

You're welcome

ruby osprey