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()