You will need to generate a new tween every time the value changes. If you combine your original script with the one you had been working on, you can get something like this:
local TweenService = game:GetService("TweenService")
local mouse = false
script.Parent.MouseButton1Down:connect(function() mouse=true end)
script.Parent.MouseButton1Up:connect(function() mouse=false end)
script.Parent.MouseLeave:connect(function(x,y) mouse=false end)
script.Parent.MouseMoved:connect(function(x,y)
if mouse then
if 10-(((y-script.Parent.AbsolutePosition.Y)/850)*1) > 2 then
script.Parent.Value.Value = 15-(((y-script.Parent.AbsolutePosition.Y)/850)*15)
else
script.Parent.Value.Value = 0
end
script.Parent.Bar.Size = UDim2.new(1, 0, ((1-((y-script.Parent.AbsolutePosition.Y)/850))), 0)
end
end)
local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.In)
script.Parent.Value.Changed:connect(function()
TweenService:Create(script.Parent.Bar,tweenInfo,{Size = UDim2.new(1, 0, (script.Parent.Value.Value/2)/100, 0)}):Play()
end)
This code generates a UDim2 corresponding to the new size the bar should be just like your original code and generates the tween from this new size and runs it. This happens within the .Changed event handler rather than outside it.
In your second post, the tween is only ever generated the first time the code runs, which is why it doesn’t change even when the value changes.
I can’t understand what you’re trying to achieve here? If you could provide some more context, maybe a gif so we can help you to the best of our ability.
Is the range of your values 0 to 15? If so, try this code:
local TweenService = game:GetService("TweenService")
local mouse = false
script.Parent.MouseButton1Down:connect(function() mouse=true end)
script.Parent.MouseButton1Up:connect(function() mouse=false end)
script.Parent.MouseLeave:connect(function(x,y) mouse=false end)
script.Parent.MouseMoved:connect(function(x,y)
if mouse then
if 10-(((y-script.Parent.AbsolutePosition.Y)/850)*1) > 2 then
script.Parent.Value.Value = 15-(((y-script.Parent.AbsolutePosition.Y)/850)*15)
else
script.Parent.Value.Value = 0
end
end
end)
local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.In)
script.Parent.Value.Changed:connect(function()
TweenService:Create(script.Parent.Bar,tweenInfo,{Size = UDim2.new(1, 0, script.Parent.Value.Value/15, 0)}):Play()
end)
This should scale the bar to whatever percentage of 15 your current value is, but I don’t know how well it will line up since the code seems to be dependent on screen size.