Unable to cast to dictionary

I am trying to tween an orb to a point, but it keeps giving me the error:
Unable to cast to dictionary
Additionally, I have read other peoples questions about this but now it says that the “=” in

Monster.CFrame = V

Is an error, and it says:

  13:35:15.147  Workspace.OrbEnemy.Humanoid.Script:13: Expected '}' (to close '{' at line 12), got '='  -  Studio - Script:13

Here is my full code:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")

local Module = require(ReplicatedStorage.Positions)

local Humanoid = script.Parent
local Monster = Humanoid.Parent

local TweenInfo = TweenInfo.new(1, Enum.EasingStyle.Linear)

for i, V in pairs(Module) do
	goal = {
		Monster.CFrame == V
	}
	local Tween = TweenService:Create(Monster, TweenInfo, goal)
	Tween:Play()
	Tween.Completed:Wait()
end

Does anybody know what’s wrong?

2 Likes

I believe the problem is your goal dictionary.
Try this:

goal = {
    CFrame = V
}

You’re setting the Monster.CFrame value inside of it. I didn’t mention the fact that you’re checking the value (Monster.CFrame == V) because in your snippet above, it was just Monster.CFrame = V. So I am assuming that you had a typo in your “full code”.

1 Like

I changed it to “==” but now I get unable to cast to dictionary, and I don’t think I have a typo in my code because I printed everything, and if there was an error, it’d probably come first. And I don’t see any.

The == operator is used when you’re checking a value. The script is probably throwing an error because the tween needs a dictionary with keys that have the names of the object your tweening’s properties. You’re currently setting goal to this:

goal = {false --[[Or `true`; depends if Monster.CFrame is equal to V.]]}

When you should be setting it to this:

goal = {CFrame = V}

If you’re still getting the error, is V a CFrame?
I see that you’re requiring a Module called Positions. So, if V is a Vector3 value, make sure you’re setting the CFrame key in goal to CFrame.new(V).

Also, the “Unable to cast” error occurs when you’re trying to pass a value as an argument (parameter, property) that it isn’t compatible with.

3 Likes

V is a cframe. I don’t know how I could make it compatible though. Here is “Positions”.

local points = workspace.Points

local positions = {
	points.Start.CFrame,
	points.Point1.CFrame,
	points.Point2.CFrame,
	points.Point3.CFrame,
	points.Point4.CFrame,
	points.End.CFrame
}

return positions

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