Search code examples
roblox

"Unable to cast to Dictionary" error occurred when trying to tween


I was trying to make a tween for a text so whenever when player loaded and wait for at least 5 seconds after they loaded in, the text transparency will set to 0 smoothly

Then, I tried to make that happen with a service called TweenService but I was greeted with an error "Unable to cast to Dictionary"

I tried another way by checking the documentation and Forums but didn't find or solve any solutions

Here's my code:

local loadingrobloxos = LoadingAssetsGUI.LoadingBootBackground.LoadingRobloxOS
local goallro = loadingrobloxos.TextTransparency == 0
local tweeninfolro = TweenInfo.new(
    0.5,
    Enum.EasingStyle.Quad,
    Enum.EasingDirection.InOut,
    1,
    false
)
local tweenlro = TweenService:Create(loadingrobloxos, tweeninfolro, goallro):Play()

What is actually wrong?


Solution

  • If you look at the documentation for TweenService:Create, you'll see that the last argument of the function is supposed to be a dictionary.

    TweenService:Create(loadingrobloxos, tweeninfolro, goallro)
    

    The error is telling you that whatever you passed in for the variable goallro, it cannot be converted to a dictionary. And that line is...

    local goallro = loadingrobloxos.TextTransparency == 0
    

    This line is not creating a dictionary, it is asking the question, "is loadingrobloxos's TextTransparency currently set to zero?" So the variable goallro is set to false. TweenService doesn't know what to do with false, so it throws the error.

    Instead, try this :

    local goallro = {
        TextTransparency = 0
    }