How would I create a tool stamina bar that decreases when a tool is used?
I think that you have to decrease the value on the server, then fire a remote event to the client
with the new value, so you can decrease the bar itself on the client.
But I am not sure how to do it so if I can have an explanation that would be nice.
Flow charts are helpful in situations like this when you're trying to figure out how a script would work. Here's what I would do:
Call a function when the tool is equipped, by using Tool.Equipped:Connect()
Somewhere in the function you'll want to have a while true do loop, remember to include a wait, to decrease the server-sided stamina value of the player. Obviously, you'll also want to fire to the client here to update the stamina gui.
Inside the loop towards the end you'll want to have an if statement to check if the stamina value has reached zero. If so, you can get the humanoid and use Humanoid:UnequipTools(). And, of course a break when the tool is deselected, either by the player or by running out of stamina.
Example to summarize:
local Player = Tool.Parent.Parent -- tool is inside backpack which is inside player local Stamina local RemoteEvent -- not sure where you have these things so I left them as empty variables, for the sake of the example local Equipped = false Tool.Equipped:Connect(function() Equipped = true -- important things pertaining to what your tool does here while true do Stamina.Value = Stamina.Value - 1 -- 1 is how much stamina is being subtracted each loop if Stamina.Value ~= 0 then RemoteEvent:FireClient(Player, Stamina.Value) -- do your gui work if Equipped = false then break end else Player.Character.Humanoid:UnequipTools() break end wait(1) end end) Tool.Unequipped:Connect(function() Equipped = false end)