Hello! Today, I’ll teach everybody how to make a Durability System!
Short Answer: Create an IntValue and when it reaches 0, the tool breaks.
– DISCLAIMER: Please understand what I’m doing and not just copy the script.
First, create your tool and add a LocalScript.
In the LocalScript, we have to make the IntValue and set it’s properties.
local value = Instance.new("IntValue") -- Creates the IntValue
value.Parent = game.ReplicatedStorage -- Sets the IntValue's Parent
value.Value = 8 -- Sets how many uses the Tool Has
Now, Let’s make the IntValue Decrease when tool is in hand and it is clicked
tool.Activated:Connect(function() -- When tool pressed
value.Value -= 1 -- remove 1 from IntValue
end)
Now, let’s remove the tool from player’s backpack (and optionally, let’s Unequip the tool first, so we don’t have any Custom animation problems)
local player = game.Players.LocalPlayer.Character
local Humanoid = player:WaitForChild("Humanoid")
if value.Value <= 0 then -- if the value is 0 or under
Humanoid:UnequipTools()
tool:Destroy() -- Destroy the tool
end
end)
And for the end, let’s add a debounce so the player doesn’t spam click.
tool.Activated:Connect(function() -- When tool pressed
if db == false then -- if the function is unlocked
db = true -- lock the function, so the player doesn't spam
wait(2) -- how much to wait, configure it how much you want.
db = false -- unlock the function
end
end)
The Final (Local)Script will be:
local tool = script.Parent -- tool
local player = game.Players.LocalPlayer.Character
local Humanoid = player:WaitForChild("Humanoid")
local value = Instance.new("IntValue") -- Creates the IntValue
value.Parent = game.ReplicatedStorage -- Sets the IntValue's Parent
value.Value = 8 -- Sets how many uses the Tool Has
db = false -- unlock the function
tool.Activated:Connect(function() -- When tool pressed
if db == false then -- if the function is unlocked
db = true -- lock the function, so the player doesn't spam
value.Value -= 1 -- remove 1 from IntValue
if value.Value <= 0 then -- if the value is 0 or under
Humanoid:UnequipTools()
tool:Destroy() -- Destroy the tool
end
wait(2) -- how much to wait, configure it how much you want.
db = false -- unlock the function
end
end)