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)