Hello, I want to make a tool where if the player holds down left click on the mouse, a progress bar should show up and slowly fill up. If the player were to let go of left click, the progress should pause and resume from where it left off until the player decides to continue holding left click again. And also prevent it from going beyond the maximum length of the progress bar GUI.
Here is my script so far:
local players = game:GetService("Players")
local player = game.Players.LocalPlayer
local tool = script.Parent
local mouse = player:GetMouse()
local handle = tool:WaitForChild("Handle")
local animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Handle.Sweep)
local MAXBar = 100
local BarProgress = 1
local bar = players.LocalPlayer.PlayerGui.SweepBar.Background.Bar
local held = false
local currentProgress = player.PlayerGui:WaitForChild("SweepBar").Progress
function updateGui()
player.PlayerGui.SweepBar.Background.Bar:TweenSize(UDim2.new(0,(currentProgress.Value/MAXBar * 246), 1, 0), "Out", "Linear", 1)
currentProgress:GetPropertyChangedSignal("Value"):Connect(function()
player.PlayerGui.SweepBar.Background.Bar:TweenSize(UDim2.new(0,(currentProgress.Value/MAXBar * 246), 1, 0), "Out", "Linear", 1)
end)
end
tool.Equipped:Connect(function(mouse)
mouse.Button1Down:Connect(function()
held = true
animation:Play()
players.LocalPlayer.PlayerGui.SweepBar.Enabled = true
end)
mouse.Button1Up:Connect(function()
held = false
end)
end)
tool.Activated:Connect(function()
tool.Handle["Broom Sound Effect"]:Play()
if currentProgress.Value < MAXBar then
while held == true do
updateGui()
currentProgress.Value = currentProgress.Value + 0.1
wait(0.1)
end
end
if currentProgress.Value >= MAXBar then
player.PlayerGui:FindFirstChild("SweepBar").TextLabel.Text = "Sweep Complete"
end
end)
tool.Deactivated:Connect(function()
tool.Handle["Broom Sound Effect"]:Stop()
animation:Stop()
players.LocalPlayer.PlayerGui.SweepBar.Enabled = false
end)
Currently with this code, the number value inside of the player’s GUI folder stays at 0 and refuses to go up. Unless I were to change the “while held == true do” part to " while true do" it seems to work, but the progress goes up extremely fast, and continues to go up infinitely beyond the progress bar’s UI. Any help or any other questions please leave a comment below. Thank you!