Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Zombie does damage to player when alive and when killed?

Asked by 7 years ago
Edited 7 years ago

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 -

01function onTouched(part)
02 
03    local h = part.Parent:findFirstChild("Humanoid")
04 
05    if h~=nil then
06 
07h.Health = h.Health - 1
08end
09 
10 
11 
12script.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

01function onTouched(part)
02 
03    local h = part.Parent:findFirstChild("Humanoid")
04 
05    if h~=nil then
06 
07h.Health = h.Health - 1
08 
09local humanoid = script.Parent:WaitForChild("Humanoid")
10if humanoid.Died:connect(function ()
11 
12    local h = part.Parent:findFirstChild("Humanoid")
13 
14    if h~=nil then
15 
View all 28 lines...

1 answer

Log in to vote
1
Answered by 7 years ago

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

01function onTouched(touched)
02    if script.Parent.Parent:FindFirstChild("Humanoid") then
03        if script.Parent.Parent.Humanoid.Health ~= 0 then
04            local humanoid = touched.Parent:FindFirstChild("Humanoid")
05            if humanoid then
06                humanoid:TakeDamage(1)
07            end
08        end
09    end
10end
11script.Parent.Touched:connect(onTouched)
Ad

Answer this question