local RemoteEvent = script.Parent:WaitForChild("RemoteEvent")
local Mouse = game.Players.LocalPlayer:GetMouse()
local Tool = script.Parent
local IsActivated
local function OnActivated ()
local Target = Mouse.Target
if Target then
local Durability = Target:FindFirstChild("Durability")
if Durability then
IsActivated = true
while IsActivated == true and Target.Parent ~= nil and Durability.Value > 0 do
wait(0.1)
Durability.Value = Durability.Value - 1
end
if IsActivated == true and Target.Parent ~= nil and Durability.Value == 0 then
RemoteEvent:FireServer(Target, Target.Value.Value)
-- focus
if IsActivated == true then
OnActivated()
end
-- focus
end
end
end
end
local function OnDeactivated ()
IsActivated = false
end
Tool.Activated:Connect(OnActivated)
Tool.Deactivated:Connect(OnDeactivated)
I don't know why this happen's but i'm pretty sure its because of the OnActivated() but im not sure, it should only run twice but it repeats a lot.
Concept : When everything goes right, it makes it so that the function would run again.
Specific : When everything goes as it is expected (IsActivated == true and Target.Parent ~= nil and Durability.Value == 0) then it would "run" the function over again.

2 comments
note : line 19 - 21 causes the error
Well, it is a bit obvious. You're calling the function in an if statement that will always be true, which causes the script to endlessly run the function since it always passes the if statement.