I Keep getting an error saying "Unable to cast to Dictionary"

Hello!

So I am currently working on a game, and there is this part. When the player touches the part, the sun begins to set, and the color of the Atmosphere and the ColorShifts Tween into a different color.

However, every time I run the game, it gives me an error saying “Unable to cast to Dictionary”.

17:21:53.149 Unable to cast to Dictionary - Server - NightObjectiveChangeScript:16

This is the Code:

print("Night Objective Change Script Start 1")

local NightObjectiveChangeEvent = game:GetService("ReplicatedStorage"):WaitForChild("NightObjectiveChangeEvent")
local NightObjectiveChangeEventAllClients = game:GetService("ReplicatedStorage"):WaitForChild("NightObjectiveChangeEventAllClients")
local Objective = game:GetService("ReplicatedStorage"):WaitForChild("Objective")
local TweenService = game:GetService("TweenService")
local Lighting = game:GetService("Lighting")
local Atmosphere = Lighting:WaitForChild("Atmosphere")
local ColorCorrection = Lighting:WaitForChild("ColorCorrection")

local LightingTween4 = TweenService:Create(Lighting, TweenInfo.new(10, Enum.EasingStyle.Linear, Enum.EasingDirection.In), { ClockTime = 17 })
local AtmosphereTween4 = TweenService:Create(Atmosphere, TweenInfo.new(10, Enum.EasingStyle.Linear, Enum.EasingDirection.In), { Density = 0.4 })

local LightingColorShift_Bottom_TweenGoal = Color3.fromRGB(255, 206, 126)

local LightingColorShift_Bottom_Tween = TweenService:Create(Lighting.ColorShift_Bottom, TweenInfo.new(10, Enum.EasingStyle.Linear, Enum.EasingDirection.In), { Color3.fromRGB(255, 206, 126) })
local LightingColorShift_Top_Tween = TweenService:Create(Lighting.ColorShift_Top, TweenInfo.new(10, Enum.EasingStyle.Linear, Enum.EasingDirection.In), { Color3.fromRGB(255, 201, 115) })
local LightingOutdoorAmbient_Tween = TweenService:Create(Lighting.OutdoorAmbient, TweenInfo.new(10, Enum.EasingStyle.Linear, Enum.EasingDirection.In), { Color3.fromRGB(204, 156, 79) })

local AtmosphereColorTween = TweenService:Create(Atmosphere.Color, TweenInfo.new(10, Enum.EasingStyle.Linear, Enum.EasingDirection.In), { Color3.fromRGB(204, 156, 79) })
local AtmosphereDecayTween = TweenService:Create(Atmosphere.Decay, TweenInfo.new(10, Enum.EasingStyle.Linear, Enum.EasingDirection.In), { Color3.fromRGB(199, 167, 94) })

local ColorCorrectionTintTween = TweenService:Create(ColorCorrection.TintColor, TweenInfo.new(10, Enum.EasingStyle.Linear, Enum.EasingDirection.In), { Color3.fromRGB(199, 167, 94) })

local Players = game:GetService("Players"):GetPlayers()

NightObjectiveChangeEvent.OnServerEvent:Connect(function()
	
	print("Night Objective Change Script Start 2")
	
	LightingTween4:Play()
	AtmosphereTween4:Play()
	LightingColorShift_Bottom_Tween:Play()
	LightingColorShift_Top_Tween:Play()
	AtmosphereColorTween:Play()
	AtmosphereDecayTween:Play()
	ColorCorrectionTintTween:Play()
	
	wait(10)
	
	Objective.Value = "Head back to your cabin"

	NightObjectiveChangeEventAllClients:FireAllClients()
end)

The output says the problem is in the Tween Variables, so I have tried changing them around, but nothing seems to work. Can anybody help me?

it’s saying it’s unable to “cast” to a dictionary since there isn’t a key assigned to this value

you need to do

{Color = Color3.fromRGB(255, 206, 126)}

and ya need to do that for all the Tweens that have that sorta dictionary

1 Like

Hey there. Thanks for replying.

It still doesn’t work after I put Color = Color3.fromRGB(color). Instead, the output gave me a different error this time.

17:27:08.390 Unable to cast value to Object - Server - NightObjectiveChangeScript:16

Now, it says “Unable to cast value to Object”. Any help for this?

The first parameter of TweenService:Create uses an Instance, and the dictionary decides which properties to be tweened. In your case, your code would need to look like this:

local ColorCorrectionTintTween = TweenService:Create(ColorCorrection, TweenInfo.new(10, Enum.EasingStyle.Linear, Enum.EasingDirection.In), { TintColor = Color3.fromRGB(199, 167, 94) })

Hey! Thanks for replying. However, the output is only saying that Line 16 is wrong.

17:27:08.390 Unable to cast value to Object - Server - NightObjectiveChangeScript:16

Now, your code might have fixed that line, but I am still not sure what is causing the other lines to break the script.

They are all having the same problem, where the first parameter of Tween:Create is using the value of the property, instead of the Instance. Try replacing line 16-23 with this:

local LightingColorShift = TweenService:Create(Lighting, TweenInfo.new(10, Enum.EasingStyle.Linear, Enum.EasingDirection.In),
	{ ColorShift_Bottom = Color3.fromRGB(255, 206, 126),
		ColorShift_Top = Color3.fromRGB(255, 201, 115),
		OutdoorAmbient = Color3.fromRGB(204, 156, 79) })

local AtmosphereTween = TweenService:Create(Atmosphere, TweenInfo.new(10, Enum.EasingStyle.Linear, Enum.EasingDirection.In),
	{ Color = Color3.fromRGB(204, 156, 79),
		Decay = Color3.fromRGB(199, 167, 94) })

local ColorCorrectionTween = TweenService:Create(ColorCorrection, TweenInfo.new(10, Enum.EasingStyle.Linear, Enum.EasingDirection.In),
	{ TintColor = Color3.fromRGB(199, 167, 94) })

Hey man! Thank you so much for your help. This worked.

1 Like

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