So I made this script and I keep the a error saying bad cast,what does it mean and how could I fix it? If you manged to fix it please show how and what you did.

Error:

bad cast

Script 'Workspace.Model.Script', Line 11

Stack End

--~-----------Vairbles---------------~--
local Model = script.Parent
---------------------------------------------   
    for Number,Part in pairs (Model:GetChildren()) do
--------------More Vairbles----------------
local PreviousPart = math.floor(Number - 1)
local PreviousPartName = "Part"..PreviousPart
local Motor = Instance.new("Motor6D",Part)
-------------------------------------------
    print(PreviousPartName)
    Motor.Part0 = Part
    Motor.Part1 = Model.PreviousPartName
    print(Motor.Part0)
    Motor.DesiredAngle = -Number
    end

The model is set up like this:

Model Setup Picture/Error

2 comments

2

A cast in programming means a type conversion. A bad cast in this case means you are trying to convert a type in a wrong way.

0

How can I convert it in the right way?