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

Object expected, got string,what?[Not Fixed]

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 comment

0

Edited for better understanding

1 answer

In line 12 you have Motor.Part1 = PreviousPartName Because of the Motor.Part1 it is looking for an object, and is registering the other section of that line: PreviousPartName as a string. Try changing it to

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

I am not entirely sure if that will work, as I am fairly new myself, but it seems like that is the issue it is having.

6 comments

0

I changed the "PreviousPartName" in line 12 to "PreviousPartName.Part" (both w/out the quotation marks). Let me know if it worked for ya!

0

It wasnt supposed to change a property. In line 12, the Motor.Part1 makes the Script look for a Part. PreviousPartName itself is a string, not a part, thus not what the Script is looking for, so it will error out. By changing it to PreviousPartName.Part you are giving it the part it is looking for instead of the string that will essentially, "confuse" the computer.

0

The property of Motor.Part1 didn't change and I got a enew error saying bad cast Script 'Workspace.Model.Script', Line 11 Stack End

0

What is it the script is trying to do?

0

I'm trying to make s snake movment thing by making the Motor6D's Part1 changing to the last previous part

0

Try using the MoveTo() function and .Position Vector3 values, it might make your time considerably easier.

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