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

My Part's Orientation sets to 0, when I CFrame it??

Basically, when you click the script, the Part is supossed to Go on a position, after 5 seconds to come back, however when it comes back, the Orientation sets to 0, how can I fix this?

local part = script.Parent


local click = script.Parent.ClickDetector

click.MouseClick:Connect(function(click)
    print("I got clicked")
part.Orientation = part.Orientation + CFrame.new(0, 90, 180)
    script.Parent.CFrame = CFrame.new(1304.292, 235.142, -665.739) 
    wait(5)
part.Orientation = part.Orientation + CFrame.new(0, 90, 180)
    script.Parent.CFrame = CFrame.new(1284.227, 237.592, -668.21)
end)

2 answers

Hello.

Solution:

Use CFrames.Angles instead of orientation as CFrames cannot be added to Orientation (Vector3). Also, CFrames are rotation and position, so you don't need to use orientation.

Fixed code:

local part = script.Parent


local click = script.Parent.ClickDetector

click.MouseClick:Connect(function(click)
    print("I got clicked")
	part.CFrame = part.CFrame * CFrame.Angles(0, math.rad(90), math.rad(180))
    script.Parent.CFrame = CFrame.new(1304.292, 235.142, -665.739)  * CFrame.Angles(0, math.rad(90), math.rad(180))
    wait(5)
part.CFrame = part.CFrame * CFrame.Angles(0, math.rad(90), math,rad(180))
    script.Parent.CFrame = CFrame.new(1284.227, 237.592, -668.21) * CFrame.Angles(0, math.rad(90), math,rad(180))
end)

6 comments

0

You can use CFrame.Angle ?

0

Somehow, it still doesn't work, the orientation sets to 0, 0, 0 >.<

0

Hold on, let me edit it. I see what you mean now.

0

Try now, I've edited it.

0

https://imgur.com/a/j0BJF65 , As always, the part's orientation sets to 0??? this is so weird

0

Try now.

Someone on Discord Helped me: This is the way how to Rotate and CFrame at the same time, and it works fine!

part.CFrame = CFrame.new(1300, 237.6, -665.8) * CFrame.Angles(0, math.rad(90), math.rad(180))

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