Why is this animation not working?

This is a simple problem, i’m trying to animate a Billboard Gui so it goes goes up and down, however, the Y Coordinate never changes, what causes this?

Here is the code:

--Variables
local Player = game:GetService("Players").LocalPlayer
local CheckPointNumber = Player:WaitForChild("CheckPointNumber")
local CheckPointFolder = game.Workspace:WaitForChild("_CheckPoints")
local BillBoard = script.Parent:WaitForChild("NextStage")
local function OnLevel() -- Ignore this pl0x
	BillBoard.Adornee = CheckPointFolder:FindFirstChild(tostring(CheckPointNumber.Value + 1))
end
CheckPointNumber.Changed:Connect(OnLevel)

function Down() --Go down
   BillBoard.ExtentsOffsetWorldSpace = Vector3.new(BillBoard.ExtentsOffsetWorldSpace.X, BillBoard.ExtentsOffsetWorldSpace.Y - 1, BillBoard.ExtentsOffsetWorldSpace.Z)
   if BillBoard.ExtentsOffsetWorldSpace.Y <= 90 then
		  BillBoard.ExtentsOffsetWorldSpace = Vector3.new(BillBoard.ExtentsOffsetWorldSpace.X, 90, BillBoard.ExtentsOffsetWorldSpace.Z)
		   Up()
   end
   if BillBoard.ExtentsOffsetWorldSpace.Y > 90 then
	  delay(1/60, function() Up() end)	
   end	
end
function Up() -- go up
   BillBoard.ExtentsOffsetWorldSpace = Vector3.new(BillBoard.ExtentsOffsetWorldSpace.X, BillBoard.ExtentsOffsetWorldSpace.Y + 1, BillBoard.ExtentsOffsetWorldSpace.Z)
   if BillBoard.ExtentsOffsetWorldSpace.Y >= 100 then
		  BillBoard.ExtentsOffsetWorldSpace = Vector3.new(BillBoard.ExtentsOffsetWorldSpace.X, 100, BillBoard.ExtentsOffsetWorldSpace.Z)
		  Down()
   end
   if BillBoard.ExtentsOffsetWorldSpace.Y < 100 then 
	  delay(1/60, function() Down() end)	
   end
end
OnLevel() --Ignore this pl0x
Down() --Start the animation

Keep in mind that this code also does some other functions, so i marked them as “ignore this pl0x” so it’s easier to track what part of the code is failling.

Any help is appreciated, thanks!

2 Likes

Just an idea but, have you tried tweening it instead?

1 Like

Yeah, but, it didn’t look that good tweening. Maybe i should retry that instead…

I think the problem is just that you are calling the opposite direction each time you call Up or Down, and it always makes the billboard move in both directions in the same frame somehow.
You can fix this by declaring Up and Down as a variable first before defining the function, that way you can reference the variable in its own function, and just differentiating through if statements instead of always calling opposite functions.

--Variables...

local EOWS = "ExtentsOffsetWorldSpace"
-- local Up, Down

local Up; function Up()
    BillBoard[EOWS] = BillBoard[EOWS] + Vector3.new(0,1,0)
    if BillBoard[EOWS].Y < 100 then
        delay(1/60, Up)
    else
        BillBoard[EOWS] = Vector3.new(BillBoard[EOWS].X, 100, BillBoard[EOWS].Z)
        delay(1/60, Down)
    end
end

local Down; function Down()
    BillBoard[EOWS] = BillBoard[EOWS] - Vector3.new(0,1,0)
    if BillBoard[EOWS].Y > 90 then
        delay(1/60,Down)
    else
        BillBoard[EOWS] = Vector3.new(BillBoard[EOWS].X, 90, BillBoard[EOWS].Z)
        delay(1/60,Up)
    end
end

--Ignore this pl0x

Keep in mind that this code will loop itself approximately once every 2/3 seconds (since delay will always wait at least 1/30 of a second, 20 iterations, 20/30), and you might want to make it slower?

Also, you would want to use tweens anyway since they change at 60 fps and have a much easier interface to work with in my opinion.
I made the equivalent code already, if you want to test it out:

local tween = TweenService:Create(
    BillBoard --object to tween
    TweenInfo.new(
        2/3, -- time
        Enum.EasingStyle.Linear,
        Enum.EasingDirection.InOut,
        -1, -- number of loops, -1 = infinity
        true, -- reverses
        0 -- delay
    ),
    --this assumes the billboard offset starts at (0,90,0)
    {ExtentsOffsetWorldSpace = BillBoard.ExtentsOffsetWorldSpace + Vector3.new(0,10,0)}
) -- :Play()
tween:Play()

I hope this helps!

1 Like

Oh yeah, just noticed that now, sometimes everyone does dumb mistakes…

1 Like