You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
I’m making a fishing game, and am currently at the casting stage where I tween the size of a progress bar up based on how long the player holdsMouseButton1, and I want to make the bar reset its size when I stop holding it down. -
What is the issue? Include screenshots / videos if possible!
For some reason this error is triggered when I start holding downMouseButton1:

-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have tried rewriting the code.
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!
My Script: (LocalScript)
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")
local player = Players.LocalPlayer
local activeTween
local function createTween(object, tweenInfo, properties)
local tween = TweenService:Create(object, tweenInfo, properties)
local activeTween = tween
tween:Play()
return tween
end
local function UpdateBarColor(bar)
local size = bar.Size.Y.Scale
local red = math.clamp(0 - size, 0, 0)
local green = math.clamp(size, 0, 1)
bar.BackgroundColor3 = Color3.new(red, green, 0)
end
local function animateBar(bar)
bar.Size = UDim2.new(Bar.Size.X.Scale, 0, 0, 0)
local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, -1, true)
local tween = createTween(bar, tweenInfo, {
Size = UDim2.new(bar.Size.X.Scale, 0,1,0),
Position = UDim2.new(bar.Position.X.Scale)
})
return tween
end
UserInputService.InputBegan:Connect(function(input, gpe)
if not gpe then
if input.UserInputType == Enum.UserInputType.MouseButton1 then
print("Began")
local UI = player.PlayerGui.FishingUi
local Main = UI.Main
local Casting = Main.Casting
local Bar = Casting.Bar
Casting.Visible = true
animateBar(Bar)
task.spawn(function()
while Casting.Visible do
UpdateBarColor(Bar)
task.wait(0.01)
end
end)
end
end
end)
UserInputService.InputEnded:Connect(function(input, gpe)
if not gpe then
if input.UserInputType == Enum.UserInputType.MouseButton1 then
print("Ended")
local UI = player.PlayerGui.FishingUi
local Main = UI.Main
local Casting = Main.Casting
local Bar = Casting.Bar
Casting.Visible = false
if activeTween then
activeTween:Cancel()
end
Bar.Size = UDim2.new(Bar.Size.X.Scale, 0, 0, 0)
Bar.Position = UDim2.new(Bar.Position.X.Scale, 0, 0, 0)
end
end
end)
