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

Punch tool does damage when not clicking?

I'm trying to make a good punch tool but even though it is unequipped and I am not clicking it still does damage to the enemy NPCs. How can I fix this? (script) I've already tried things like: -tool.Activated -debounce

Here's the script:

local tool = script.Parent
local hitsound = tool:WaitForChild("Hit")
local canattack = tool:WaitForChild("CanAttack")
local plr = tool.Parent.Parent
local char = plr.Character or plr.CharacterAdded:wait()
local larm = char:WaitForChild("LeftHand")
local rarm = char:WaitForChild("RightHand")

larm.Touched:Connect(function(hit)
	local hum = hit.Parent:FindFirstChild("Humanoid")
	if canattack.Value == false then
		if hum then
			canattack.Value = true
			hitsound:Play()
			hum:TakeDamage(10)
			wait(.5)
			canattack.Value = false
		end
	end
end)
rarm.Touched:Connect(function(hit)
	local hum = hit.Parent:FindFirstChild("Humanoid")
	if canattack.Value == false then
		if hum then
			canattack.Value = true
			hitsound:Play()
			hum:TakeDamage(10)
			wait(.5)
			canattack.Value = false
		end
	end
end)

1 answer

✓ Accepted answer

You should try raycasting renderstep on both arms, and if it finds a humanoid, the humanoid takes 10 damage. https://developer.roblox.com/en-us/articles/Making-a-ray-casting-laser-gun-in-Roblox https://devforum.roblox.com/t/raycasting-how-do-i-do-it/186446

2 comments

1

This would be your best bet. And for future reference, the "touched" event runs every time you touch something so you would need to somehow verify it is in equipped before taking damage.

0

Thanks! It works

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