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

My script makes the zombie attack,but doesn't anymore when he gets hit, why?

Asked by 4 years ago
Edited 4 years ago
db = false
script.Parent.Touched:connect(function(hit) 
pcall(function() 
    if db == false then
        db = true
hit.Parent.Humanoid:TakeDamage(50)
wait(1)
db = false
wait(1)
db = true
end
end) 
end)

My script works, except for the fact that when the zombie is hit, he no longer does any damage. Does anyone know why? Should this be in a loop? Edit: Wait no it only hits once now?

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

It could have been due to your Debounce which you set to true after the script has run making it not work any longer, you should also check if the Touched part has a Humanoid in the first place. You don't want this to trigger if the zombie touches something such as a wall which would return nil. Try this.

db = false
script.Parent.Touched:Connect(function(hit)
    if db == false then
        if hit.Parent:FindFirstChild("Humanoid") then
            hit.Parent.Humanoid:TakeDamage(50)
            wait(1)
            db = false
        end
    end
end)
0
OMG TYSM! It didnt work at first, but I added a line after line 5 to make db = true. Thanks, heres ur karma! Trisodin529 89 — 4y
0
Glad I was able to help! JoyfulPhoenix 139 — 4y
Ad

Answer this question