Unable to Cast to Dictionary - Tweening & Module Script Error

I am trying to build an elevator and I’m using tween service to close the doors after a player presses the down button. I am using a module script for the Vector3 values and I am requiring the module and naming the variable, “S” (for settings).

This is the code for the down button. I keep getting the error, “Unable to Cast to Dictionary” in the tween1 variable.

Also, the variables in tween1 are from above, and I assigned the variables of outerdoor, innerdoor, tweenInfo, and tweenProp1 to a certain variable in the settings module using the S variable.

Why is my code not working and giving me the Unable to Cast to Dictionary error?

Here is a picture of the settings module:

Hi, unfortunately I’m not sure on the exact technical reasons for this, but I came across the same problem when creating the TweenInfo in a module to pass into another function. I think once the TweenInfo is created as a new object in its class, the module passes a reference to it, rather than the actual TweenInfo itself.
I found the way round it is to simply create the TweenInfo inside the script in which it will be used.

Are you saying that I should create the tweeninfo inside the actual script not the settings module? If so, I will give that a try.

Yes. I know it is not the solution you were hoping for, but at least it works.

It didn’t work, I just tested it. It still said that it was unable to cast to dictionary. I don’t know why it isn’t working. Here is my current code.

Also, the Vector3 Values for where the door is tweening to are in the module script, if that helps. (They are also referred to as, “S.OUTERDOOR_CLOSE_POS_1”)

Ok, the Tween properties look like they might not be formatted correctly.
Try putting the vector3 into the format

{ Position = Vector3.new(…) }

Thank you so much - it worked! I appreciate your help and I will use this as a learning lesson for next time!

Thanks, me too, you could try moving the tweeninfo back to the module as that may not have been an issue after all.

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