I'm making this loading Gui and the loading bar won't tween properly it stops around (0,0.8, 0,0) and stays there and won't go back to start. Why does it do this and how do I fix it?
Localscript:
--------------------------- function CreateLoadingBar() local LoadingFrame = script.Parent.TextLabel.LoadingFrame local Found = LoadingFrame:FindFirstChild("LoadingBar") if not Found then local LoadingBar = Instance.new("Frame",LoadingFrame) LoadingBar.Name = "LoadingBar" LoadingBar.Size = UDim2.new(0,50,0,35) LoadingBar.Position = UDim2.new(0,340,0,0) return LoadingBar else return Found end end --------------------------- local Finish = UDim2.new(0,0,0,0) local Start = UDim2.new(0,340,0,0) Loaded = false --------------------------- repeat wait() LoadingBar = CreateLoadingBar() print("Loading") LoadingBar:TweenPosition(Finish,"InOut","Linear",0.5,true) if LoadingBar.Position == Finish then print("Loading Bar hit Finish,putting back to start") LoadingBar:TweenPosition(Start,"Out","Linear",0.5,true) elseif LoadingBar.Position == Start then print("Loading Bar hit start,putting back to finish") LoadingBar:TweenPosition(Finish,"InOut","Linear",0.5,true) end until Loaded == true print("Done")
It is actually your repeat statement. When you tween a Gui, it doesn't wait until the tween finishes to move on, the script moves right ahead. What is happening is that it is constantly calling the first tween position, resulting it ending up in a position that the tween is less than a pixel, thereby making it immobile.
Here is the solution I came up with:
--------------------------- function CreateLoadingBar() local LoadingFrame = script.Parent.TextLabel.LoadingFrame local Found = LoadingFrame:FindFirstChild("LoadingBar") if not Found then local LoadingBar = Instance.new("Frame",LoadingFrame) LoadingBar.Name = "LoadingBar" LoadingBar.Size = UDim2.new(0,50,0,35) LoadingBar.Position = UDim2.new(0,340,0,0) return LoadingBar else return Found end end --------------------------- local Finish = UDim2.new(0,0,0,0) local Start = UDim2.new(0,340,0,0) Loaded = false --------------------------- function Mover() wait() LoadingBar = CreateLoadingBar() --print("Loading") LoadingBar:TweenPosition(Finish,"InOut","Linear",0.5,true) repeat wait() until LoadingBar.Position == Finish print("Loading Bar hit Finish,putting back to start") LoadingBar:TweenPosition(Start,"Out","Linear",0.5,true) repeat wait() until LoadingBar.Position == Start print("Loading Bar hit start,putting back to finish") LoadingBar:TweenPosition(Finish,"InOut","Linear",0.5,true) if Loaded ~= true then Mover() end end spawn(Mover) print("Done")
what happens here is that, at each transition, it waits until it gets to where it is needed, then moves on. If Loading
is false, then it will repeat itself. Hopefully this was helpful.