Melee script isn't working as Intended

So, I am having an issue with my melee script. When you press M1, It causes the script to fire and all, which shouldn’t happen unless you have the tool equipped, I am a little lost.

Basically, Tool isn’t equipped, Press LMB, avatar plays animation and deals damage, regardless of holding a specific tool or not.

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local debounce = false

mouse.Button1Down:Connect(function()
	
	if debounce == false then
		debounce = true
		local character = player.Character
		local humanoid = character:WaitForChild("Humanoid")
		local animation = character.Humanoid:LoadAnimation(script.Parent.Attack)
		animation:Play()
		
		humanoid.WalkSpeed += 4
		
		local success, msg = pcall(function()
			local target = mouse.Target

			local dist = (character.HumanoidRootPart.Position - target.Parent.HumanoidRootPart.Position).Magnitude 

			if target.Parent.Humanoid and target.Parent ~= character and dist < 4 then
				game.ReplicatedStorage.MeleeDamage:FireServer(target , 1, 16)
			end
		end)
		wait(.9)		
		humanoid.WalkSpeed -= 4
		animation:Stop()
		debounce = false
	end
end)

Hey! There is a event called “Activated” which bassically is the equavilent to what you’re trying to do right now.

Bassically,
Instead of mouse.Button1Down:Connect(function(), you’d rather want to do tool.Activated:Connect(function()

I always had the same error thank you very much even if it was not for me the favor

1 Like

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