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

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

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

✓ Accepted answer

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)

2 comments

0

OMG TYSM! It didnt work at first, but I added a line after line 5 to make db = true. Thanks, heres ur karma!

0

Glad I was able to help!

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