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

I get an error when trying to clone a model?


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?

4 comments

0

how do i post this in lua text?

0

Wrap the code in a code block

0

You need to set the model's PrimaryPart and set the CFrame using SetPrimaryPartCFrame https://www.robloxdev.com/api-reference/function/Model/SetPrimaryPartCFrame

2 answers

✓ Accepted answer

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!

2 comments

0

It is recommended that you position objects using CFrame instead of Position.

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.


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()

2 comments

0

You have a model?

0

Yes, Tracks is a model.

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