Try using Orientation.X instead of Y. The way orientation works is that the axis represents the pivot, not the actual direction it is rotating in.
Rotating around the Y axis is like walking around a vertical pole, you’re not rotating so you face upwards or downwards, you’re rotating so you change which horizontal direction you look at.
So, following this logic, both the X and Z axes represent the vertical direction you are looking in, as they are both like poles lying on the ground. This is also why you rotate vertically using the X axis in CFrame.Angles().
In this case, the X axis is what you want to read from since it is what you rotated by.
The -math.rad(90) is to rotate the model, so it’s upright (for some reason the model gets rotated without it) and then math.rad(Rotation) is to preserve the models orientation, which is what gets changed
If I got rid of the -math.rad(90) this is what I get
And if you look at the first vid, you can see my main problem. When I move the model, it rotates automatically, it should stay facing the same way when I move it
Ah, damnit, my bad, I’ve become rusty with Roblox’s transformation system Looks like I’ll need to get myself refreshed on it… I probably won’t be of any help anytime soon then, sorry.
Although… judging by your code it might be a good idea to stop using orientation entirely and just work with a ‘rotation’ variable. Or split up your code better so that you can understand the effects of normals and on it better.
Regardless of my advice, usually when it comes to problems like this, I find it is good to deconstruct everything step by step. Look into different ways of doing things. Sometimes clumping things together can make it difficult.
Not sure, but this could possibly be fixed by getting the object space orientation
Example:
local osOrientation=Model.PrimaryPart.CFrame:vectorToObjectSpace(Model.PrimaryPart.Orientation)
This returns a vector3 value which is the object space orientation, while by default you get the world space rotation.
So basically in this case osOrientation.Y is what you are looking for.
Again, not sure if that will work, but I guess it’s worth trying.
Cause the rotation by default is 0 in the variable, when I change its rotation it changes the variable. However, when the script reloads, the models rotation stays at say 180 degrees, but the scripts Rotation variable is at 0, so that’s why I need the Rotation variable to get the rotation from the model and not just be a pre set number
That’s silly. You’re just adding 45 to whatever the rotation is. There is no reason it can’t work with a negative number. Also, that’s why your Orientation.Y is -45. -45 is the exact same as 315.
The green button is to move the model, the rotate function is NEVER being fired in this video
As you can see, everytime I move it, it rotates around 90 degrees on it’s own for no reason.
And this is why having Rotation = 0 didn’t work previously, as everytime I click off this model the GUI gets deleted, and thus the script and when I reclick a new gui is added, with new script, and thus new Rotation variable
Can you please post a video of what happens when you rotate the model around the “Y” axis. I have a suspicion on something.
Also, the root of your issue would seem to lie in the fact that you delete the script everytime you get rid of the gui. I have no clue why you decided to do this.
Edit: Also include screenshot of the PrimaryPart selected with rotate tool enabled. (Make sure to be in local rotation mode)
I’ve just removed it and the line below it and it no longer rotates 90 degrees each time. If it’s to align it to the slope of the surface below it, that’s not how you should be doing it afaik.
If I understand you correctly you want to model rotate to the camera?
If so this should work.
Model:SetPrimaryPartCFrame(
CFrame.new(NewPos, NewPos + Normal) * --no reason to do Normal*15, has the same effect as Normal
CFrame.new(0, Model.PrimaryPart.Size.Y / 2, 0) *
CFrame.Angles(0, 0, math.rad(yRot))
)
(Sorry for no tabs, when I press tab it doesn’t want to place it for some odd reason)