Tween Not Working

Hello, I’m working with a custom loading script and I’ve ran into a problem. The Tween does not work at ALL. I’ve tried 4 different methods and they all haven’t worked. Please tell me whats going on

-- Load --
local Bar1 = LoadUi:WaitForChild('Bar1')
local Bar2 = LoadUi:WaitForChild('Bar2')
local Bar3 = LoadUi:WaitForChild('Bar3')
-- Inos --
local TweenIno = TweenInfo.new(0.3,Enum.EasingStyle.Quint,Enum.EasingDirection.Out)
local MaxGoal = {Size = UDim2.new(0.157,0,0.801,0),Position = UDim2.new(0.732,0,0.519,0)}
local MinGoal = {Size = UDim2.new(0.157,0,0.249,0),Position = UDim2.new(0.244,0,0.806,0)}
-- Tween --
while Bar1.Visible do
	TweenSerivce:Create(Bar1,TweenIno,MaxGoal):Play()
	task.wait(0.1)
	TweenSerivce:Create(Bar1,TweenIno,MinGoal):Play()
	task.wait(0.1)
end
---

1 Like

you spelled TweenService wrong lol

1 Like

1 Like

I think that you need to connect the part in the while loop to an event. as it is now, you check once if the bar is visible when the script first runs, and never check again. so it will not run.

try replacing the loop part with this:

local playing = false
Bar1.Changed:Connect(function()
    if playing or not Bar1.Visible then return end
    playing = true
    while Bar1.Visible do
        TweenSerivce:Create(Bar1,TweenIno,MaxGoal):Play()
        task.wait(0.1)
        TweenSerivce:Create(Bar1,TweenIno,MinGoal):Play()
        task.wait(0.1)
    end
    playing = false
end)

I’m sayin like the bar is already enabled so. What would be changing for it to detect?

image

if its already visible when this script runs then im not sure why it wouldn’t run the loop. try putting a print statement inside the loop to see if it runs

while Bar1.Visible do
        print('running')
	TweenSerivce:Create(Bar1,TweenIno,MaxGoal):Play()
	task.wait(0.1)
	TweenSerivce:Create(Bar1,TweenIno,MinGoal):Play()
	task.wait(0.1)
end

Perhaps you got them playing too fast wait(0.1)?
Try: task.wait(0.3)

Didn’t print anything sadly (char2.0)

Do you want me to show you the whole script cause they’re more lines.

1 Like
-- Services --
local Players = game:GetService('Players')
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local TweenSerivce = game:GetService('TweenService')
-- Variables --
local Player = Players.LocalPlayer
local Character = Player.Character
local Camera = workspace.Camera
-- Remotes --
local RemoteFolder = ReplicatedStorage:WaitForChild('RemoteEvents')
local KillEvent = RemoteFolder:WaitForChild('KillEvent')
-- UI --
local CompassUi = script.Parent:WaitForChild('CompassFrame')
local DiedUi = script.Parent:WaitForChild('DiedFrame')
local LoadUi = script.Parent:WaitForChild('LoadFrame')
---

-- Compass --
local LastY = 0
local Units = {[CompassUi:WaitForChild("North")] = - math.pi * 1.00,[CompassUi:WaitForChild("NorthEast")] = - math.pi * 0.75,
	[CompassUi:WaitForChild("East")] = - math.pi * 0.50,[CompassUi:WaitForChild("SouthEast")] = - math.pi * 0.25,
	[CompassUi:WaitForChild("South")] = math.pi * 0.00,[CompassUi:WaitForChild("SouthWest")] = math.pi * 0.25,
	[CompassUi:WaitForChild("West")] =  math.pi * 0.50,[CompassUi:WaitForChild("NorthWest")] = math.pi * 0.75,}
-- Functions --
function Restrict(Angle)
	if Angle < - math.pi then
		return Angle + math.pi * 2
	elseif Angle > math.pi then
		return Angle - math.pi * 2
	else
		return Angle
	end
end
-- Loops --
while CompassUi.Visible do
	local WaitTime = task.wait(0.001)
	-- Camera --
	local LookVector = Camera.CoordinateFrame.LookVector
	local Look = Vector3.new(LookVector.X,0,LookVector.Z).Unit
	local LookY = math.atan2(LookVector.Y,LookVector.Z)
	-- Restrict --
	local RestrictY = Restrict(LookY - LastY)
	LookY = Restrict(LastY + RestrictY * WaitTime * 30/10)
	LastY = LookY
	-- For Statement --
	for Unit,Rotation in pairs(Units) do
		Rotation = Restrict(LookY - Rotation)
		-- Move UI --
		if math.sin(Rotation) > 0 then
			local CosRotation1 = math.cos(Rotation)
			local CosRotation2 = CosRotation1 * CosRotation1
			-- Visibility --
			Unit.Visible = true
			Unit.Position = UDim2.new(0.5 + CosRotation1 * 0.6,Unit.Position.X.Offset,0,3)
			Unit.TextTransparency = - 0.25 + 1.25 * CosRotation2
		else
			Unit.Visible = false
		end
	end
end
---

-- Load --
local Play = false
local Bar1 = LoadUi:WaitForChild('Bar1')
local Bar2 = LoadUi:WaitForChild('Bar2')
local Bar3 = LoadUi:WaitForChild('Bar3')
-- Inos --
local TweenIno = TweenInfo.new(0.3,Enum.EasingStyle.Quint,Enum.EasingDirection.Out)
local MaxGoal = {Size = UDim2.new(0.157,0,0.801,0),Position = UDim2.new(0.732,0,0.519,0)}
local MinGoal = {Size = UDim2.new(0.157,0,0.249,0),Position = UDim2.new(0.244,0,0.806,0)}
-- Tween --
while Bar1.Visible do
	TweenSerivce:Create(Bar1,TweenIno,MaxGoal):Play()
	task.wait(0.3)
	TweenSerivce:Create(Bar1,TweenIno,MinGoal):Play()
	task.wait(0.3)
end
---

yeah show the whole script. If nothing is printing it means that when the script gets to the loop, the Bar1 is not visible so the loop doesnt run

oh, its probably because the compass loop never stops running so the script never past it to play your other tweens

This checks to see if it exits while Bar1.Visible do
This checks to see if it’s true while Bar1.Visible == true

So would I have to make the loading a script itself or what can I do?

you can use task.spawn(function) for each loop to play them in seperate threads so it doesnt yield your script.

i think a better way than that is to use coroutines but i dont know how to use them so i couldnt help with that.

Like this?

local Thread = coroutine.create(function()
   while Bar1.Visible do
   	TweenSerivce:Create(Bar1,TweenIno,MaxGoal):Play()
   	task.wait(0.3)
   	TweenSerivce:Create(Bar1,TweenIno,MinGoal):Play()
   	task.wait(0.3)
   end
end)
coroutine.resume(Thread)
---

yes that should work. do it to your compass loop too

1 Like

It workedddddd :heart: Thank you (char2.0)

2 Likes