Hi, so what I am trying to achieve is a door that opens/closes whenever you get near it and press E.
I have a local script on the player and it detects whenever the player hits E, and when he does, he fires a remote event, which then a script inside the door picks up the remote event and rotates the door to open, then waits 4 seconds, and then closes it once again. I made the script as generic as possible so that I can just clone the door and not need to change any of the values.
Here is the script inside the door.
local door = script.Parent
local hinge = door.Hinge
local doorsize = door.Size
local startrot = door.Orientation
local startpos = door.Position
local cooldown = false
game.ReplicatedStorage.InteractE.OnServerEvent:Connect(function(player)
local humanrootpart = player.Character:FindFirstChild("HumanoidRootPart")
local playerdistance = (door.Position - humanrootpart.Position).Magnitude
if playerdistance <= door.BillboardGui.MaxDistance and cooldown == false then
cooldown = true
for i = startrot.Y,startrot.Y+90 do
door.CFrame = CFrame.new(hinge.Position) * CFrame.Angles(startrot.X,math.rad(i),startrot.Z) * CFrame.new(0,0,(doorsize.Z/2))
wait()
end
wait(4)
for i = startrot.Y+90,startrot.Y,-1 do
door.CFrame = CFrame.new(hinge.Position) * CFrame.Angles(startrot.X,math.rad(i),startrot.Z) * CFrame.new(0,0,(doorsize.Z/2))
wait()
end
wait(1)
cooldown = false
end
end)
So basically whenever the player is in reach of the door, he can press E and the door will rotate, but this is what happens instead:
The door opens correctly but slightly tilts forwards.
This is how the door’s orientation looks BEFORE opening:

and this is how it looks AFTER opening it:

The Y rotation worked, it added 90 to it but for some reason, the Z orientation got rotated 26.62 degrees and I don’t understand why.
BTW, the hinge is for the door to rotate on it.
Any help would be appreciated. Thanks