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

Why is my Damage Script doing no damage to people?

This script is inside of a part that is inside of the player. It's supposed to damage other players that it comes in contact with. It's not doing any damage for whatever reason. What am I doing wrong? (Explanations please)

local deb = false

script.Parent.Touched:Connect(function(hit)
	local OtherHumanoid = hit.Parent:FindFirstChild("Humanoid") or hit.Parent.Parent:FindFirstChild("Humanoid")
	local PlayersHumanoid = script.Parent.Parent:FindFirstChild("Humanoid")
	if OtherHumanoid == PlayersHumanoid then OtherHumanoid = nil
	if OtherHumanoid ~= nil then
		if deb == true then return end
		deb = true
		OtherHumanoid.Health = OtherHumanoid.Health-50
		wait(0.2)
		deb = false
		end
	end
end)

3 comments

0

why would workspace have a humanoid (hit.Parent.Parent)

0

First make sure your script is not local. Other possibilty is that part is being bombarded with touch events from same character body parts..

0

@EXpodo1234ALT that's in case it accidentally hits an object like a hat.

1 answer

✓ Accepted answer

This script is pretty easy to fix. I assume you should know everything below. If not, just comment and I can explain.

local debounce = false

script.Parent.Touched:Connect(function(hit)
	local humanoid = hit.Parent:FindFirstChild("Humanoid")

	if humanoid then
		if not debounce then
			debounce = true
			humanoid:TakeDamage(50)
			wait(0.2)
			debounce = false
		end
	end
end)

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