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!