Tween not playing

I want the loading screen to tween out of the screen after the game is loaded.

I keep getting an error saying “Unable to cast to Dictionary” which I don’t know what means lol.

Code

if game:IsLoaded() then
	textLabel.Text = "Loaded!"
	wait(2)
	local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
	local tween1 = TweenService:Create(textLabel, tweenInfo, {Vector3.new(-0.004, 0,-0.982, 0)})
	tween1:Play()
end

Thats where the error is coming from

The code is a local script inside ReplicatedFirst.

Any errors?

The 3rd argument of TweenService:Create() should be a dictionary of properties. Also pretty sure textlabels don’t have any property that accept a Vector3, you probably meant to use a UDim2

{Size = UDim2.new(-0.004, 0,-0.982, 0)}
-- or
{Position = UDim2.new(-0.004, 0,-0.982, 0)}

PS, GuiObjects have their own Tween methods for simplicity

3 Likes

Now it doesn’t give me the error so you fixed the error, but it still isn’t playing my tween. It just vanishes. I think it’s the tween itself but I don’t know what could be wrong.

The tween is probably just playing way too fast, you could just implement something like another yielding function so that it waits until that specific Instance is found

You’re tweening to a negative scale value so that’s probably what’s causing it to go off-screen

It should be UDim2, since it is a 2d object:

{Position = UDim2.fromScale(-0.004,-0.982)}

And if not, why does Vector3 have 4 numbers?

I want it to go off screen but upwards and acting like it’s out of the screen. Then it’s destroyed.

Try tweening it to 0, 0, 0, 0 maybe. -0.982 is almost 1 whole screen height upwards and the tween time is only 1 second so it probably tweens so fast you can’t really see it… Or maybe you’re not yielding until the tween is completed and destroying the label instantly?

It is still being destroyed instantly even though I added a wait before it is destroyed.

if game:IsLoaded() then
	textLabel.Text = "Loaded!"
	wait(2)
	local tweenInfo = TweenInfo.new(4, Enum.EasingStyle.Bounce, Enum.EasingDirection.Out)
	local tween1 = TweenService:Create(textLabel, tweenInfo, {Position = UDim2.new(0, 0, 0, 0)})
	tween1:Play()
end

if not game:IsLoaded() then
	game.Loaded:Wait()
end

wait(5)

screenGui:Destroy()

It’s probably the if statement logic

local function Loaded()
	textLabel.Text = "Loaded!"
	wait(2)
	local tweenInfo = TweenInfo.new(4, Enum.EasingStyle.Bounce, Enum.EasingDirection.Out)
	local tween1 = TweenService:Create(textLabel, tweenInfo, {Position = UDim2.new(0, 0, 0, 0)})
	tween1:Play()
end

if game:IsLoaded() then
	Loaded()
else
	game.Loaded:Wait()
	Loaded()
end

wait(5)

screenGui:Destroy()

Still the same thing, I will provide a video here.

Here is my error:

YouTube - Loading Screen

Well, it’s kinda hard to debug stuff like this without knowing your whole setup. Maybe it’s some other code causing this or maybe the anchor point of the textlabel is weird? It could be anything, I don’t really know… Any chance you could send the place file with just the gui code?

  1. I did some debugging and made the wait before before the GUI to be destroyed to become 20 seconds. It turns out, the tween just doesn’t play at all.

  2. Here is my full code:

local Players = game:GetService("Players")
local ReplicatedFirst = game:GetService("ReplicatedFirst")
local TweenService = game:GetService("TweenService")

local player = Players.LocalPlayer 
local playerGui = player:WaitForChild("PlayerGui")

local screenGui = Instance.new("ScreenGui")
screenGui.IgnoreGuiInset = true
screenGui.Parent = playerGui
local textLabel = Instance.new("TextLabel")
textLabel.Size = UDim2.new(1, 0, 1, 0)
textLabel.BackgroundColor3 = Color3.fromRGB(0, 9, 128)
textLabel.Font = Enum.Font.GothamSemibold
textLabel.TextColor3 = Color3.new(255,255,255)
textLabel.Text = "Loading"
textLabel.TextSize = 28
textLabel.Parent = screenGui
local loadingRing = Instance.new("ImageLabel")
loadingRing.Size = UDim2.new(0, 256, 0, 256)
loadingRing.BackgroundTransparency = 1
loadingRing.Image = "rbxassetid://4965945816"
loadingRing.AnchorPoint = Vector2.new(0.5, 0.5)
loadingRing.Position = UDim2.new(0.5, 0, 0.5, 0)
loadingRing.Parent = screenGui


ReplicatedFirst:RemoveDefaultLoadingScreen()

local tweenInfo = TweenInfo.new(4, Enum.EasingStyle.Linear, Enum.EasingDirection.In, -1)
local tween = TweenService:Create(loadingRing, tweenInfo, {Rotation = 360})
tween:Play()

wait(7)

local function Loaded()
	textLabel.Text = "Loaded!"
	wait(2)
	local tweenInfo = TweenInfo.new(4, Enum.EasingStyle.Bounce, Enum.EasingDirection.Out)
	local tween1 = TweenService:Create(textLabel, tweenInfo, {Position = UDim2.new(0, 0, 0, 0)})
	tween1:Play()
end

if game:IsLoaded() then
	Loaded()
else
	game.Loaded:Wait()
	Loaded()
end

wait(20)

screenGui:Destroy()

Okay just change the tween Position to UDim2.new(0, 0, -1, 0) Lol. You should also probably parent the loading ring to the text label so they move together

1 Like

Thank you! It works now and it looks sick!