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

How to make a npc do damage not just set health to a point?

So I have a npc that follows you but the script makes it so it just brings your health to a point.

local function onTouch(Touch)
 	if Touch.Parent:FindFirstChild("Humanoid") ~= nil then
		Touch.Parent.Humanoid.Health = 0
	
	end
end


script.Parent.HumanoidRootPart.Touched:Connect(onTouch)

So it would set your health to 0, but I want to make it do say 2 damage on hit. How would I accomplish this?

4 comments

0

Ask if you need the other script like the following script or animation script in the npc

0

Touch.Parent.Humanoid.Health = Touch.Parent.Humanoid.Health -10 for example

0

Touch.Parent.Humanoid.Health = Touch.Parent.Humanoid.Health -10 for example

0

I would mark this as the answer but you commented it....... It worked though

1 answer

✓ Accepted answer
local debounce = false
local function onTouch(Touch)
    if Touch.Parent:FindFirstChild("Humanoid") ~= nil then
	if not debounce then
		debounce = true
	        Touch.Parent.Humanoid.Health =  Touch.Parent.Humanoid.Health - 2
		wait(0.1)
		debounce = false
	end
    end
end


script.Parent.HumanoidRootPart.Touched:Connect(onTouch)


You need debounce so it will be 2 damage every 0.1 seconds.

2 comments

0

Touched only fired when an object starts touching, you never even set debounce to true, and you need to learn to press Tab more.

0

This is just mistake, I edited it.

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