TweenService Unable to cast dictionary for DayNight System

I’m trying to smoothly change the clocktime from 14.5 to 3 using this code

local TweenService = game:GetService("TweenService")
local CycleTime = 10
local Frames = 100
local Clocktime = game.Lighting.ClockTime

local Info = TweenInfo.new(
	CycleTime,
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.Out,
	Frames,
	false,
	0
)
local NightGoal = Clocktime == 3
local SetClockToNight = TweenService:Create(Clocktime, Info, NightGoal) ---Where I'm getting my error

wait(10)
SetClockToNight:Play()

In the output tab I’m getting " Unable to cast to Dictionary " line 22 which is the SetClockToNight line

Can someone explain why I’m getting this error please? Thanks

local NightGoal = Clocktime == 3
local NightGoal = {ClockTime = 3}

‘goal’ parameter should be a dictionary of properties and values.

TweenService:Create(game.Lighting, Info, NightGoal)
1 Like

You need to put in the Instance you are tweening as the first argument of TweenService:Create(), so you wouldn’t do TweenService:Create(ClockTime), you’d do TweenService:Create(Lighting, Info, {ClockTime = 3})

I did this and now I’m getting unable to cast value to object

Make sure the first argument is game.Lighting or a variable which is a reference to the ‘Lighting’ service also ‘Clocktime’ needs to be ‘ClockTime’.

1 Like