Weird additional touch delay

Hi I’m trying to make a side melee system for my weapons and it goes smooth but with a little additional touch delay error.

Basically I want to make two sounds which one is for a fist swing sound and another for a struck sound and the problem is where if I do a swing but then touch a humanoid it still has the previous function which should had ended.

This is what it looks like which has an additional damage which shouldn’t happened:

This is the server script I made:

local function Weapon_Melee_Function()
	local Weapon_Melee_Sound = Weapon_Sounds:WaitForChild("Weapon_Melee_Sound")
	Weapon_Melee_Sound:Clone().Parent = Handle.Parent.Parent:FindFirstChild("Left Arm")
	Handle.Parent.Parent:FindFirstChild("Left Arm"):FindFirstChild("Weapon_Melee_Sound"):Play()
	Handle.Parent.Parent:FindFirstChild("Left Arm"):FindFirstChild("Weapon_Melee_Sound").Ended:Once(function()
		Handle.Parent.Parent:FindFirstChild("Left Arm"):FindFirstChild("Weapon_Melee_Sound"):Destroy()
	end)
	Handle.Parent.Parent:FindFirstChild("Left Arm").Touched:Once(function(Weapon_Melee_Function)
		if Weapon_Melee_Function.Parent:FindFirstChild("Humanoid") then
			print("Humanoid")
			local Weapon_Struck_Sound = Weapon_Sounds:WaitForChild("Weapon_Struck_Sound")
			Weapon_Struck_Sound:Clone().Parent = Handle.Parent.Parent:FindFirstChild("Left Arm")
			Handle.Parent.Parent:FindFirstChild("Left Arm"):FindFirstChild("Weapon_Struck_Sound"):Play()
			Handle.Parent.Parent:FindFirstChild("Left Arm"):FindFirstChild("Weapon_Struck_Sound").Ended:Once(function()
				Handle.Parent.Parent:FindFirstChild("Left Arm"):FindFirstChild("Weapon_Struck_Sound"):Destroy()
			end)
			Weapon_Melee_Function.Parent.Humanoid.Health -= 5
		end
	end)
end

I have tried some stuff to move the touched function but still no luck.

1 Like

So I’ve kind of made a temporary value inside the script as like a temporary gate that uses the true and false Boolean which somehow ended up working but with exceptional sound durations.

This is the script I came up with:

local Weapon_Melee_Action = false

local function Weapon_Melee_Function()
	Weapon_Melee_Action = true
	local Weapon_Melee_Sound = Weapon_Sounds:WaitForChild("Weapon_Melee_Sound")
	Weapon_Melee_Sound:Clone().Parent = Handle.Parent.Parent:FindFirstChild("Left Arm")
	Handle.Parent.Parent:FindFirstChild("Left Arm"):FindFirstChild("Weapon_Melee_Sound"):Play()
	Handle.Parent.Parent:FindFirstChild("Left Arm"):FindFirstChild("Weapon_Melee_Sound").Ended:Once(function()
		Handle.Parent.Parent:FindFirstChild("Left Arm"):FindFirstChild("Weapon_Melee_Sound"):Destroy()
		Weapon_Melee_Action = false
		print(Weapon_Melee_Action)
	end)
	Handle.Parent.Parent:FindFirstChild("Left Arm").Touched:Once(function(Weapon_Struck_Function)
		if Weapon_Struck_Function.Parent:FindFirstChild("Humanoid") and Weapon_Melee_Action == true then
			print(Weapon_Melee_Action)
			local Weapon_Struck_Sound = Weapon_Sounds:WaitForChild("Weapon_Struck_Sound")
			Weapon_Struck_Sound:Clone().Parent = Handle.Parent.Parent:FindFirstChild("Left Arm")
			Handle.Parent.Parent:FindFirstChild("Left Arm"):FindFirstChild("Weapon_Struck_Sound"):Play()
			Handle.Parent.Parent:FindFirstChild("Left Arm"):FindFirstChild("Weapon_Struck_Sound").Ended:Once(function()
				Handle.Parent.Parent:FindFirstChild("Left Arm"):FindFirstChild("Weapon_Struck_Sound"):Destroy()
			end)
			Weapon_Struck_Function.Parent.Humanoid.Health -= 5
			Weapon_Melee_Action = false
		end
	end)
end

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