Problem With function repeating [re-upload]

im creating a Sword For The Client Side But When I try to kill the enemy (the enemy is client side) it kills him right away and the enemy has 3 health

the script in the sword:

local Sword = script.Parent
local Handle = Sword.Handle

local Debounce = false

function TakeDamage(hit)
	local Humanoid = hit.Parent:FindFirstChild("Humanoid")
	if Humanoid and Humanoid.Health >= 1 then
		Humanoid:TakeDamage(1)
	end
end

Sword.Activated:Connect(function()
	if Debounce == false then
		Debounce = true
		Handle.SwordSlash:Play()
		local TakeDamage = Handle.Touched:Connect(TakeDamage)
		wait()
		TakeDamage:Disconnect()
		wait(1)
		Debounce = false
	end
end)

Sword.Equipped:Connect(function()
	Handle.Unsheath:Play()
end)

thanks for the collaboration :slightly_smiling_face:

As you are disconnecting takedamage, and only require it run once, you can use :Once() instead of :Connect()

The issue is the wait() delaying the disconnect for 2 steps, meaning by the time it actually disconnects it has fired the touched even three times.

i’m sorry you got late i’ve fixed it now :sweat_smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.