Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Object expected, got string,what?

I'm trying to make this snake animation thing with Mortor6D ,but I got a error in the output,what does it mean and how could I fix it?

If you can give me tips on how to make this script organized it will be appreciated and if you manged it fix please show how.

The error in the output is:

Workspace.Model.Script:12: bad argument #3 to 'Part1' (Object expected, got string)

Script 'Workspace.Model.Script', Line 12

Stack End

The script:

--~-----------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 = PreviousPartName
    print(Motor.Part0)
	Motor.DesiredAngle = -Number
    end

I have the model setup like this:

Model Picture

1 answer

✓ Accepted answer

You are assigning the name of the last part to Motor.Part1 when you should be assigning the previous part to it. The fix is this:

--~-----------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] -- <-- Edited the script here
    print(Motor.Part0)
    Motor.DesiredAngle = -Number
    end

This discussion is preserved as it was. New answers, comments, and votes are closed.