LocalScript detecting death only sometimes?

Just as the title says, my LocalScript that plays a random sound when the player dies is not triggering when the player dies in certain ways rather than others, in this case, the sounds play when the player falls to their death, but not when they are killed by an NPC in my game

this is my code for random death sounds:

local rndd = {d1, d2, d3, d4}

humanoid.Died:Connect(function()
	rndd[math.random(1, #rndd)]:Play()
end)

and this is the code for the NPC to kill me:

while true do
	wait(0.01)
	target = findNearestTorso(script.Parent.Torso.Position)
	if target ~= nil then
		target:ChangeState(15)
	end
end

(yes i know that doing ‘while true’ and ‘while wait()’ is really not good, it isnt affecting performance yet so meh)

and this is the code for falling to my death:

if new == Enum.HumanoidStateType.Landed and deadlyfall == true and root.Velocity.Y < -120 then
		humanoid:ChangeState(15)
	elseif new == Enum.HumanoidStateType.Landed and root.Velocity.Y > -120 then
		deadlyfall = false
	end
end)

i have a feeling that it could be due to the fact that the falling death script is a LocalScript like the random death sound script, and that the NPC script is not a LocalScript, but a regular Script, but i would have no idea what to do about that anyway. if anyone has the answer to this i would be greatful!

are there any errors?

also, try adding a print() in the humanoid.Died event and sees if that works. if it prints every time, then its something wrong with your sounds.

make sure the sounds are parented to a body part of the character so the player can actually hear it

also try disabling other scripts

I figured out what the problem was, my separate ragdoll code which was making the playermodel become a child of the workspace rather than the player after death was firing too quickly for the RNG death sound code which made it not fire, not sure why it was firing when i died of falling still though lol, i just added a short delay to the ragdoll code, thanks for suggesting to disable other scripts!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.