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

Is there a way to change a models position in a script?

Since models don't have position, or rotation in the properties i don't know i would make a script to move a models position in the workspace.

--basically what i want but with a model
Part.Position = Vector3.new(1,3,5)

if somone could explain this to me that would be great!

1 answer

✓ Accepted answer

It is pretty simple. Since models have a PrimaryPart, many model functions provided by ROBLOX use this part as reference.

##1. Setting your own primary part It is the pretty simple. Click on the PrimaryPart and select the part you want as the primary part. Done! If you didn't understood, click here

##2. :MoveTo() Moves the center of the PrimaryPart to the position you given to it. Any other parts the model contains will follow it. Uses Vector3.new()

game.Workspace.Model:MoveTo(Vector3.new(1,1,1)) - moves the PrimaryPart to 1,1,1

However, since it uses Vector3, if the position isn't free of any obstacles, the part will be moved on Y axis until a "free" zone is found.

##3. :SetPrimaryPartCFrame() Basically the same thing as :MoveTo(), but ignores any obstacles, and you may rotate it. NOTE that if you don't set a rotation, it is reset to 0,0,0!. By other side, the rotation input is on radians and not degrees! Uses CFrame.new() and CFrame.Angles()

game.Workspace.Model:SetPrimaryPartCFrame(CFrame.new(1,1,1)) * CFrame.Angles(math.pi, math.pi/2, math.pi) - moves the PrimaryPart to 1,1,1, and rotation to 180,90,180.

The formula to convert degrees into radians is r = math.pi*(d/180), in wich d is the value in degrees, and r is the value in radians. You could use math.rad() to convert, but I wouldn't recommend that.

Hope I helped!

1 comment

0

Thanks a lot! Now i can finally finish my script

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