I’m trying to tween the purple loading bar to the left if the value is going to 0 and vice versa (right when its going above 0)
(Additional information starting value was 0 which means the purple loading bar is fully tweened to the right.)
local Value = game:GetService("ReplicatedStorage").Value
Value.Changed:Connect(function(Val)
game:GetService("TweenService"):Create(script.Parent.Parent.loadingbar, TweenInfo.new(1), {Size = UDim2.new(Value.Value/Val,0,1,0)}):Play()
end)
Sorry I meant the actual values, it’s just they set the width by scale, so anything above 1 will be full width (or more without a UI constraint).
Either;
The .changed event isn’t firing - check with a print statement.
The tweenInfo is missing parameters - unlikely as it should use the defaults.
The x.scale value in the UDim2 is too high - so val / max to get a proportional value.
Anyways, I think what I see wrong is that you should instead get the UDim2 Size of the Frame and then subtract or do whatever you want to do. Something like this?
local TS = game:GetService("TweenService")
local Bar = script.Parent.Parent.loadingbar
TS:Create(Bar, TweenInfo.new(1), {Size = Bar.Size - UDim2.new(Value.Value/Val,0,1,0)}):Play()
I edited my previous post,
You will need to create a proportional value from the Val and a Maximum value that it shouldn’t exceed but does reach, if you want it to reach the end.
Or as it is a countdown timer, you can use the starting value of the countdown timer as the Max.
How exactly, I’ve decided to use the 900 value for the count down only, not sure about the bar though.
I use a similar structure in a different bar.
local __CONTENTPROVIDER = game:WaitForChild("ContentProvider")
local loadables = workspace:GetDescendants()
local amount_loaded = 0
for i = 1, #loadables do
__CONTENTPROVIDER:PreloadAsync({loadables[i]})
amount_loaded = i
script.Parent.Parent.Size = UDim2.new(amount_loaded/#loadables,0,1,0)
end
local Value = game:GetService("ReplicatedStorage").Value
local Max = 900 --your starting time allowance for countdown
Value.Changed:Connect(function(Val)
game:GetService("TweenService"):Create(script.Parent.Parent.loadingbar, TweenInfo.new(1), {Size = UDim2.new(Val/Max,0,1,0)}):Play()
end)
As it counts down from 900 it calculates 900 / 900 = 1 i.e. full width, until 0 / 900 = 0 i.e. no width.
It should rescale towards the anchor point, so I would move this as required and reposition the loading bar based on that, as it is easier.
Edit: still typing as you posted. Yes like that basically.
local MaxTime = 900 -- Change this to whatever you want
local LoadingBar = script.Parent.Parent.loadingbar
local Value = game:GetService("ReplicatedStorage").Value
Value.Changed:Connect(function(Val)
game:GetService("TweenService"):Create(LoadingBar, TweenInfo.new(0.2), {Size = UDim2.new(Val/MaxTime,0,1,0)}):Play()
end)
Not sure, without knowing the ancestry of the elements, but the gap could be padding in the parent element.
For this arrangement I would have the yellow background as the parent of the loading bar and the timer to make sure they were all contained inside.