I made a script that was like long until Validark made it shorter. And two things: Thank you Validark and also, I am having problems with it for some reason. It is not doing what I want it to do. What I wanted it to do was to rotate without making the part position up. When I clicked it, it rotated good, but instead, the part went from 1.981 to 2.481. I want it to stay the same no matter where you put the radio. Also, on the -9.37 for positon or CFrame
, I put it there to move it back to make the rotation better and to line it up. That position should happen on the rotation where it says 173.413. Also I want that to work if I ever move it. Because, if I publish it as a model, people or I might put it in a different place which will mess up the positioning a little.
--Validark Answered Script (Thank you) local cover = game.Workspace.Radio.Cover local slot = game.Workspace.Radio.Slot debounce = false --Creates a table of values local rotationXValues = {-180, 179, 178, 177, 176, 175.9, 175.413, 174.413, 173.413, 172.413, 171.413, 170.413, 169.413, 168.413, 167.413, 166.413, 165.413, 164.413, 163.413, 162.413, 161.413, 160.413, 155.413, 150.413, 145.413, 140.413, 135.413, 130.413, 125.413, 120.413, 115.413, 110.413, 105.413, 104.413, 103.413, 102.413, 101.413, 100.413, 99.413, 98.413, 97.413, 96.413, 95.413, 94.413, 93.413, 92.413, 91.413, 90.293} function onClicked() if not debounce then debounce = true for a,v in pairs(rotationXValues) do --This "for" loop runs through each value of the table cover.CFrame = CFrame.new(cover.CFrame.X, 1.981, -9.37) cover.Rotation = Vector3.new(v, 0, -180) wait(.1) end debounce = false end end script.Parent.ClickDetector.MouseClick:connect(onClicked)
I hope you understand. Validark if you are reading this, thank you and I hope you understand as well and help as well. Again, thank you.
If you want it to stay in the same place, just remember where it started:
local home = cover.CFrame ........ cover.CFrame = home cover.Rotation = Vector3.new(v, 0, 180)
EDIT:
A problem is that when you set Rotation
, the part will be shoved up to not intersect any parts. That means we have to put it in the right place after setting the rotation.
We can save the target orientation
, then move it to the position of home
:
cover.CFrame = home cover.Rotation = Vector3.new(v, 0, 180) local orientation = cover.CFrame - cover.Position cover.CFrame = orientation + home.p
For the list you also must use ipairs
, not pairs
. pairs
will not go over a list in order.
While the list of values is much better than the individual statements, a function for the exact position would be much, much better.
It seems like approximately a cosine would work:
for t = 0, 4.8, 0.03 do wait(0.03) local v = math.cos(t / 4.8 * math.pi) * 45 + 90 + 45 cover.CFrame = home cover.Rotation = Vector3.new(v, 0, 180) local orientation = cover.CFrame - cover.Position cover.CFrame = orientation + home.p end
This completely eliminates the need for a giant list of numbers, which is impossible to tweak.