"Unable to cast to dictionary" Error

Hello! I am fairly new to scripting, (As you can probably see by my group) and I was wondering if anyone could help with an error that keeps popping up in my output called “Unable to cast to dictionary” I am trying to create an egg hatching system, so help would be appreciated.

Section of code:

local tweenInfo = TweenInfo.new(
		2,
		Enum.EasingStyle.Bounce,
		Enum.EasingDirection.Out,
		0,
		false,
		0	
	)
	local tween = TweenService:Create(camera, tweenInfo, {CFrame = CFrame.new(petClone.PrimaryPart.Position + (petClone.PrimaryPart.CFrame.lookVector * 5) + Vector3.new(0,0.75,0)),petClone.PrimaryPart.Position})
	tween:Play()
	wait(5)
	
		for i, v in pairs(studio.Confetti:GetChildren()) do
		if v:IsA("ParticleEmitter") then
			v.Enabled = false
		end
	end

(Please tell me if I posted this in the wrong topic. Thanks!)

Change

{CFrame = CFrame.new(petClone.PrimaryPart.Position + (petClone.PrimaryPart.CFrame.lookVector * 5) + Vector3.new(0,0.75,0)),petClone.PrimaryPart.Position})

To

{CFrame = CFrame.new(petClone.PrimaryPart.Position + (petClone.PrimaryPart.CFrame.lookVector * 5) + Vector3.new(0,0.75,0),petClone.PrimaryPart.Position)})

(All I changed was where you placed the closing parenthesis. Note that the final parenthesis that is in that line of script is for the tweenService:Create(), so don’t remove it.)

I can’t get this code to be formatted correctly. Sorry!

When I hatch an egg, it still is not showing the pet in the game, just the output. You fixed the error, (Thank you so much!) but is there a way you could help me with that? That would be greatly appreciated if possible.

1 Like

The only script you sent was the tween so there isn’t really much I can do about an “egg hatching”

Oh, I can send you the whole thing. (Of course, only if you have time)

Script:

local TweenService = game:GetService("TweenService")

local camera = game.Workspace.Camera
local studio = game.Workspace.Studio

local template = script:WaitForChild("Template")
local scrollingFrame = script.Parent:WaitForChild("Pets"):WaitForChild("ScrollingFrame")
local function addToFrame(pet)
	local newTemplate = template:Clone()
	newTemplate.Name = pet.Name
	newTemplate.PetName.Text = pet.Name
	newTemplate.Parent = scrollingFrame
	
	local newPet = pet:Clone()
	newPet.Parent = newTemplate.ViewportFrame
	
	local camera = Instance.new("Camera")
	camera.CFrame = CFrame.new(newPet.PrimaryPart.Position + (newPet.PrimaryPart.CFrame.lookVector * 3), newPet.PrimaryPart.Position)
	camera.Parent = newTemplate.ViewportFrame
	
	newTemplate.ViewportFrame.CurrentCamera = camera
	
end

game.ReplicatedStorage.HatchEgg.OnClientEvent:Connect(function(player,pet)	
	addToFrame(pet)
	camera.CameraType= Enum.CameraType.Scriptable
	camera.CFrame = studio.CamPart.CFrame
	
	wait (1.5)
	
	for i = 1, 50, 1 do
		studio.Egg.Size = studio.Egg.Size + Vector3.new(0.,10.1,0.1)
		wait(0.01)
	end
	
	
	local explosion = Instance.new("Explosion")
	explosion.BlastRadius = 10
	explosion.BlastPressure = 0
	explosion.Position = studio.Egg.Position
	explosion.ExplosionType = Enum.ExplosionType.NoCraters
	explosion.DestroyJointRadiusPercent = 0
	
	explosion.Parent = studio.Egg
	
	studio.Egg.Transparency = 1
	
	local petClone = pet:Clone()
	for i, v in pairs(petClone:GetChildren()) do
		if v:IsA("BasePart") then
			v.Anchored = true
		end
	end
	for i, v in pairs(petClone:GetChildren()) do
		if v:IsA("ParticleEmitter") then
			v.Enabled = true
		end
	end
	petClone:SetPrimaryPartCFrame(CFrame.new(studio.Egg.Position,studio.CamPart.Position))
	petClone.Parent = studio
	
	local tweenInfo = TweenInfo.new(
		2,
		Enum.EasingStyle.Bounce,
		Enum.EasingDirection.Out,
		0,
		false,
		0		
	)
	local tween = TweenService:Create(camera, tweenInfo, {CFrame = CFrame.new(petClone.PrimaryPart.Position + (petClone.PrimaryPart.CFrame.lookVector * 5) + Vector3.new(0,0.75,0),petClone.PrimaryPart.Position)})
	tween:Play()
	wait(5)
	
		for i, v in pairs(studio.Confetti:GetChildren()) do
		if v:IsA("ParticleEmitter") then
			v.Enabled = false
		end
	end
	
	camera.CameraType = Enum.CameraType.Custom
	studio.Egg.Transparency = 0
	studio.Egg.Size = Vector3.new(6.283, 7.97, 6.663)
	petClone:Destroy()
	
end)