Cutscene unable to cast value to object

Hey, so I am making a cutscene for my game and I have everything set up. I tried to code a script to where once the player joins the game, the cutscene will play. Unfortunately, I get an error of “Unable to cast value to object

The error happens at this part of the script:

Entire script:

local cutsceneChar = workspace.CutsceneIntro.CutsceneChar


local animationId = 12790291872


local animationTrack = cutsceneChar.Humanoid:LoadAnimation(animationId)
animationTrack:Play()


local fadeInTime = 2
local fadeOutTime = 2


local fadeGui = Instance.new("ScreenGui")
local fadeFrame = Instance.new("Frame")
fadeFrame.BackgroundTransparency = 1
fadeFrame.Size = UDim2.new(1, 0, 1, 0)
fadeFrame.BackgroundColor3 = Color3.new(0, 0, 0)
fadeFrame.Parent = fadeGui
fadeGui.Parent = game:GetService("Players").LocalPlayer:WaitForChild("PlayerGui")

local tweenInfo = TweenInfo.new(fadeInTime, Enum.EasingStyle.Linear)
local tween = game:GetService("TweenService"):Create(fadeFrame, tweenInfo, {BackgroundTransparency = 1})
tween:Play()


animationTrack.Completed:Wait()


local tweenInfo = TweenInfo.new(fadeOutTime, Enum.EasingStyle.Linear)
local tween = game:GetService("TweenService"):Create(fadeFrame, tweenInfo, {BackgroundTransparency = 0})
tween:Play()


tween.Completed:Wait()
fadeGui:Destroy()

You need to create an Animation object rather than just using the animationId as the argument. So you would need something like this:

local animationObj = Instance.new("Animation")
animationObj.AnimationId = "robloxassetid://" .. animationId
local animationTrack = cutsceneChar.Humanoid:LoadAnimation(animationObj)
animationTrack:Play()
1 Like

Also, use the animator of the humanoid, not the humanoid unless it will not work

1 Like

I receive another error of “Invalid animation id ‘<error: unknown AssetId protocol>’:

what did I do wrong? Also, I used Humanoid.Animator like Haso said.

2 Likes

You can remove the .. animationId if you’re already adding the id in the string.

1 Like

It still says the same error with or without it

Do "rbxassetid://" and then your animation ID.

like this?

Problem is your animation ID has robloxassetid in it.

It would return an error.

Replace robloxassetid with rbxassetid.

1 Like

It’s fixed! Although, I have another issue, but I can’t talk about it unless I make another post. Thanks though.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.