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

I keep getting (nil value) when trying to rotate a part, how do I fix this?

Asked by 4 years ago

game.Workspace.part.Orientation =

I've tried

game.Workspace.yeet.Orientation = Orientation.new(x,y,z) didnt work and some others.

(I'm starting to script btw)

2 answers

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

If you just want to move the part then just utilize Vector-3 If you want to use another datatype which is used to alternate the Orientation. Then we use CFrame.

Lets start by printing the CFrame

local Part = script.Parent
print(Part.CFrame)

Now this may look confusing but it's not. We are printing where the block is, including the orientation.

Now we want to change the CFrame by doing this.

local Part = script.Parent
Part.CFrame = Part.CFrame * CFrame.Angles(0,math.rad(45),0)

"Why are we setting the CFrame equals to itself, times the degree, and why do we use math.rad???

Good question.

If we just do like this

local Part = script.Parent
Part.CFrame = CFrame.Angles(0,math.rad(45), 0)

It wont work, because it does not know what to do with the Part.CFrame, so that's a brief background why you set it to itself

Now, why math.rad

Well math.rad converts it into degrees so if we just did

local Part = script.Parent
Part.CFrame = CFrame.Angles(0, 45, 0)

It would think we wanted to move it.

Here is the full script

local Part = script.Parent
Part.CFrame = CFrame.Angles(0,math.rad(45), 0)

Hope you learned something new!

Ad
Log in to vote
0
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

Orientation is not an existing datatype. The datatype required must match the datatype you're trying to cast a new to, since Orientation is a three-dimensional vector, we need to cast a Vector3 datatype instead.

local Part = workspace.yeet
Part.Orientation = Vector3.new(0,0,0)

Answer this question