Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I get an error when trying to clone a model?

Asked by 6 years ago

local part = game.Workspace.Tracks local cloned = part:Clone() cloned.Parent = game.Workspace

function hit () cloned.position = Vector3.new(0,0,0) end

script.Parent.Touched:connect(hit)


whenever i do this, i get the error "position is not a valid member of model" I know what this is saying, but how do I get around this?

0
how do i post this in lua text? guywithapoo 81 — 6y
0
Wrap the code in a code block User#19524 175 — 6y
0
You need to set the model's PrimaryPart and set the CFrame using SetPrimaryPartCFrame https://www.robloxdev.com/api-reference/function/Model/SetPrimaryPartCFrame hellmatic 1523 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

You simply are forgetting that models don't have Position. Position is capitalized. Either put a block inside of the model and move that, or put a block inside the model and make it the primary part and move that. You should also not that :connect() is deprecated. Use :Connect() instead. To post code, all you need to do is place the code inside of the two lines that are provided. Example (imagine the ' are the lines provided when you click the code block button):

'''''''''''''''''

-- code

'''''''''''''''''

Here we use the real method with your fixed script:

local part = game.Workspace.Tracks
local cloned = part:Clone()
cloned.Parent = game.Workspace
local function hit() -- it is recommended that you localize your functions
    cloned.position = Vector3.new(0,0,0)
end
script.Parent.Touched:Connect(hit)

Info on localizing your functions here. If you have any additional questions feel free to post them in the comments below. I hope I helped and have a great day scripting!

0
It is recommended that you position objects using CFrame instead of Position. User#21908 42 — 6y
0
Inside of the model I have many parts. Are you saying I will need to move every single one individually? And also whats the deal with Primary part, I dont understand. guywithapoo 81 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

local part = game.Workspace.Tracks local cloned = part:Clone() cloned.Parent = game.Workspace function Hit() cloned.Position = CFrame.new(0,0,0) -- Use CFrame instead of Vector3 end script.Parent.Touched:Connect(Hit) -- Use :Connect() instead of :connect()
0
You have a model? AswormeDorijan111 531 — 6y
0
Yes, Tracks is a model. guywithapoo 81 — 6y

Answer this question