Hi! I recently got into scripting and I ran into a problem…
What do you want to achieve?
I want the blood effect to run when the zombie dies.
What is the issue?
It won’t actually start the particle system when it dies???
wait()
local hum = script.Parent:FindFirstChild("Humanoid")
local torso = script.Parent:FindFirstChild("HumanoidRootPart")
local head = script.Parent:FindFirstChild("Head")
DB = false
local function onTouch(hit)
if DB then return end
if hit == nil then return end
if hit.Parent == nil then return end
local vhum = hit.Parent:FindFirstChild("Humanoid")
if vhum ~= nil then
if hum.Health <= 0 then return end
if vhum ~= hum and not hit.Parent:FindFirstChild("ZombieScript") then
vhum:TakeDamage(math.random(6, 9))
DB = true
wait(1)
DB = false
end
end
end
torso.Touched:connect(onTouch)
local zombienoises = {93591696, 208668860, 179266532, 229895387, 150076506}
local moan = head:FindFirstChild("Moan")
while head ~= nil do
wait(math.random(6, 13))
moan.Pitch = math.random(8, 10)/10
moan.SoundId = "rbxassetid://"..tostring(zombienoises[math.random(1, #zombienoises)])
moan:Play()
end
if script.Parent.Humanoid.Health <= 0
script.Parent.HumanoidRootPart.Blood.Rate = 10000000
script.Parent.HumanoidRootPart.Blood2.Rate = 10000000
script.Parent.HumanoidRootPart.Blood3.Rate = 10000000
wait(1)
script.Parent.HumanoidRootPart.Blood.Rate = 0
script.Parent.HumanoidRootPart.Blood2.Rate = 0
script.Parent.HumanoidRootPart.Blood3.Rate = 0
end
What solutions have you tried so far?
I tried changing the “script.Parent.Humanoid.Health <= 0” to “script.Parent.Humanoid.Health = 0” but it wouldn’t work.
This is likely not working because the snippet of code (the blood effect) is never running because your loop above it is yielding the script , did you mean for the condition to go inside the loop? like:
while head ~= nil do
wait(math.random(6, 13))
moan.Pitch = math.random(8, 10)/10
moan.SoundId = "rbxassetid://"..tostring(zombienoises[math.random(1, #zombienoises)])
moan:Play()
if script.Parent.Humanoid.Health <= 0 then
script.Parent.HumanoidRootPart.Blood.Rate = 10000000
script.Parent.HumanoidRootPart.Blood2.Rate = 10000000
script.Parent.HumanoidRootPart.Blood3.Rate = 10000000
wait(1)
script.Parent.HumanoidRootPart.Blood.Rate = 0
script.Parent.HumanoidRootPart.Blood2.Rate = 0
script.Parent.HumanoidRootPart.Blood3.Rate = 0
end
end
The loop you have running above that snippet must terminate at some point before even reaching that logic. You would probably have better luck with Humanoid.Died since it fires when the health is depleted.
Maybe keep the rate at 10000000 and just make each particle “blood.Enabled = true/false” ?
Edit: Also the if statement must be in a function / event because it only checks the health once when the game starts, maybe putting it in a function and calling it when it dies?
Check output and do a test and print what script.Parent.Humanoid.Health is somewhere in your while loop in your script to ensure the condition is ever true and debug from there. if all else fails you can try connecting a died event.
i am amusing you still have a then after your condition, after it was mentioned by @Spooce that it was missing, if not that’s a problem. (i’ve now edited my post to reflect that)