New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
1

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

Asked by 14 days 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)

3 answers

Log in to vote
0
Answered by 14 days ago
Edited 14 days 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
Feahren 3677 Moderation Voter Community Moderator
14 days ago
Edited 14 days 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)
Log in to vote
-1
Answered by 14 days ago

instead of putting Orientation.new(x,y,z) put:

game.Workspace.yeet.Orientation = Vector3.new("Put the values you want to put here")

Answer this question