Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Zombie does damage to player when alive and when killed?

i make a zombie and when it is alive it does a certain amount of damage to a player. But when the player kills it and steps on it, it does the same amount of damage it originally did even though it died. here is the original script for the zombie damage -

function onTouched(part)

	local h = part.Parent:findFirstChild("Humanoid")

	if h~=nil then

h.Health = h.Health - 1
end



script.Parent.Touched:connect(onTouched)

here is the script i made to make it so when the zombie dies it doesnt so any damage to the player still

-DOESNT WORK PLEASE FIX

function onTouched(part)

	local h = part.Parent:findFirstChild("Humanoid")

	if h~=nil then

h.Health = h.Health - 1

local humanoid = script.Parent:WaitForChild("Humanoid")
if humanoid.Died:connect(function () 
	
	local h = part.Parent:findFirstChild("Humanoid")

	if h~=nil then

h.Health = h.Health - 0
	
	end
end)


	end

end



script.Parent.Touched:connect(onTouched)

1 answer

✓ Accepted answer

Here, I wrote you a new script. I hope a can learn from it. You may want to add a denounce: http://wiki.roblox.com/index.php?title=Debounce

function onTouched(touched)
	if script.Parent.Parent:FindFirstChild("Humanoid") then
		if script.Parent.Parent.Humanoid.Health ~= 0 then
			local humanoid = touched.Parent:FindFirstChild("Humanoid")
			if humanoid then
				humanoid:TakeDamage(1)
			end
		end
	end
end
script.Parent.Touched:connect(onTouched)

This discussion is preserved as it was. New answers, comments, and votes are closed.