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

So, I'm trying to make a sword to 10 damage at a time. Any help?

2 answers

✓ Accepted answer

You need to have a debounce.

local dmg = 10
local debounce = false

script.Parent.Touched:connect(function(hit)
	local char = hit.Parent
	local human = char:FindFirstChild("Humanoid")

	if human then
		if debounce == false then
			debounce = true
			
			human:TakeDamage(dmg)
			
			wait(*time in between attacks*)
			debounce = false
		end
	end
end)

1 comment

0

oops i didnt see the script

Here, use this script that I made some changes to:


local ATTACK_DAMAGE = 10
local ATTACK_DELAY = 1

local rarm = script.Parent:FindFirstChild('Right Arm')
local larm = script.Parent:FindFirstChild('Left Arm')

local debounce = false

function dmg(hit)
	if debounce == false then

	if hit and hit.Parent then --You don't have to do "hit ~= nil" .This works the same too.
	local char = hit.Parent
	if char:FindFirstChild('Humanoid') then
		debounce = true
		local hum = char.Humanoid
		hum:TakeDamage(ATTACK_DAMAGE)
		wait(ATTACK_DELAY)
		debounce = false
	end

	end
end
rarm.Touched:connect(dmg)
larm.Touched:connect(dmg)

Read this wiki for more information: https://wiki.roblox.com/?title=Debounce

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