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

How do I move a part using a script?

Asked by 4 years ago

Should I use position, CFrame, Vector3, or what? I have a camera script in game.StarterPlayer.StarterPlayerScripts.CameraScript. It changes the camera to be at a part, the part is in Workspace. The part is called CameraPart. I want to move the Camera aka CameraPart. The camera script works. But, the move CameraPart script does not work. Please help.

Here is my camera script:

wait(2.01)
local CurrentCamera = workspace.CurrentCamera
local Part = workspace.CameraPart

CurrentCamera.CameraType = Enum.CameraType.Scriptable
CurrentCamera.CFrame = Part.CFrame
wait(.25)
local CurrentCamera = workspace.CurrentCamera
local Part = workspace.CameraPart

CurrentCamera.CameraType = Enum.CameraType.Scriptable
CurrentCamera.CFrame = Part.CFrame

Here is my move CameraPart script:

wait(10)
script.Parent.Position = -29.5, 14.5, 103.5

2 answers

Log in to vote
1
Answered by 4 years ago

psst if this answered your question do hit that accept answer button below!!11!!11!!11

You're attempting to assign the Position property to -29.5.

Remember that in multiple assignment, additional results get silently discarded.

  • When there are more identifiers than expressions, the remaining variables/table fields get nil
local a, b, c = 1 -- b and c get nil
  • When the reverse occurs (more expressions than identifiers), the expression list is adjusted to the length of the identifier list, the remaining expressions are silently discarded
local a = 1, 2 -- 2 is discarded, a gets 1

You use the Vector3.new constructor function to create a new instance of a Vector3:

script.Parent.Position = Vector3.new(-29.5, 14.5, 103.5)
0
The part does move, but the camera doesnt. GamingWithFlight 80 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

I know this may sound rude but... Isn't this the first beginner's lessons of scripting?

script.Parent.Position = Vector3.new(-29.5, 14.5, 103.5)  --This would move the part to the current coordinates.

Not sure if you meant moving like with an animation as tween service...

P.S remove the comments (the ones that start with 2 divides (--) or don't.. it doesn't really matter...

Answer this question