I am making a durability system for my tool. However, the durability bar itself does not seem to be updating.
What is the issue?
Along with durability, there is a bar (Frame) that should inform you on how much durability a tool has left. This does not seem to be updating.
What solutions have you tried so far?
I tried changing the script up, and tried multiple different methods to resize the Frame, but soon realized that all modifications of the bar, including Color3 changes, did not manipulate the bar at all.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
(As you can tell, the green bar is not changing)
(Durability changes located in other scripts in the tool, that itself works)
task.wait(0.5)
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local Gui = script.Parent
local MainFrame = Gui.MainFrame
local DurabilityBar = MainFrame.DurabilityBar
local Tool = Gui.Parent
local Durability = Tool:GetAttribute("Durability")
local DefaultSizeX = 440
local SizeSpacings = Durability / DefaultSizeX
Gui.Parent = LocalPlayer.PlayerGui
Gui.Enabled = false
Tool.Equipped:Connect(function()
Gui.Enabled = true
end)
Tool.Unequipped:Connect(function()
Gui.Enabled = false
end)
Tool:GetAttributeChangedSignal("Durability"):Connect(function() --THIS IS THE MAIN FOCUS!!
DurabilityBar.Size = UDim2.new(0, SizeSpacings * DurabilityBar, 0, 10)
end)
SizeSpacings only seems to be defined at the start of the script, so for when the attribute changed signal fires, it still is just multiplying it by the same SizeSpacings value you defined at the start (the value of your variable Durability isn’t changing at all)
I meant for the “SizeSpacings” as an increment, and it was supposed to be multiplied with durability, but I guess I wasn’t careful when pressing tab
also unfortunately, this suggestion you made didn’t quite work, thanks regardless
the problem with your code is that SizeSpacings’ value was never going to change.
This is because Durability’s value is never going to change, since it only got defined once, at the start of the script:
Tool:GetAttribute doesnt listen for changes, it isnt the same as doing something like NumberValue.Value
In order to have a functionality like this you would have to do
local Durability = function() return Tool:GetAttribute("Durability") end
and
local SizeSpacings = function() return Durability() / DefaultSizeX end
you misunderstand what I mean, the variable in your localscript named Durability was never going to change, the Durability attribute is going to change however.
These are not the same, when you define it as a variable with :GetAttribute() you are storing a copy of its value in that particular moment