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
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”.
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 CFramekey 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.