I have a lever in my game that rotates everytime a character touches it
It worked but when I decided to use collectionservice instead to keep things clean the lever now rotates like this:
I tried many things to fix the issue like using
CFrame.fromEularAnglesYXZ
CFrame.Angles
I tried with and without math.rad
Adding 60 degree to the lever(Not resetting its current rotation)
It seems like there is something I don’t know about CFrames that makes it rotate like this
Also When I change Rotation of the lever(a part in the lever model not the whole model)
from (60,180,0) to (120,180,0) It rotates as i want it but orientation changes to (60,0,-180)
I have no idea why this happens
Here is the current script:
local CollectionService = game:GetService("CollectionService")
local Debounce = {}
for i,v in CollectionService:GetTagged("Lever") do
v:WaitForChild("Lever")
v.Lever.Touched:Connect(function(hit)
--V is the model and v.lever is the cylinder in the lever
if hit.Parent:FindFirstChild("Humanoid") and not Debounce[v] then
local LeverHandle = v.Handle
local Angle = CFrame.fromEulerAnglesYXZ(math.rad(60),0,0)
LeverHandle.CFrame = CFrame.new(LeverHandle.Position) * Angle
Debounce[v] = true
end
end)
end
I would really appreciate any help or any piece of information that could help
Tell me if anything isn’t clear
I think the orientation u used (LeverHandle.CFrame = CFrame.new(LeverHandle.Position) * Angle) isn’t correct, wich explains the problem you’re encountering.
It’s the whole thing in the middle
I noticed something for some reason When I use
LeverHandle.Orientation = Vector3.new(120,0,180)
It works fine without any issues but although I got the result I wanted I am really curious on why this happens I don’t wanna just do the solution without knowing why it happens
If you have any idea tell me please
Yea but x and z works yea? You can convert vector to cframe by using cframe.new and use the vector3 as a parameter. If you are using math.rad, consider removing them to see if it works
I don’t know how to use vector3 as a parameter to adjust the angle all what I see errors because the game thinks this is cframe.lookat but somehow works(with tons of errors)