use CFrame.Angles() instead of setting the Orientation of that part, as it'll try to move around objects in its way. :connect() is deprecated, use :Connect(); deprecation
basic example:
local part = game.Workspace.F5T6
local open = false
local function onTouch(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if open == false then
part.CFrame = part.CFrame * CFrame.Angles(0,math.rad(90),0)
open = true
else
part.CFrame = part.CFrame * CFrame.Angles(0,-math.rad(90),0)
open = false
end
end
end
script.Parent.Touched:Connect(onTouch)
from what i see here that you want the door to swing smoothly, instead of just opening instantly. for this you could use lerp, though you'd need to have a hinge for the door to attach too and group it together and set the PrimaryPart to the hinge.
local part = game.Workspace.Model
local open = false
local debounce = true
local function onTouch(hit)
if hit.Parent:FindFirstChild("Humanoid") and debounce == true then
if open == false then
debounce = false
local setTurning = part.PrimaryPart.CFrame * CFrame.Angles(0,math.rad(90),0)
for i = 0,1,0.1 do
local lerping = part.PrimaryPart.CFrame:Lerp(setTurning,i)
part:SetPrimaryPartCFrame(lerping)
wait()
end
open = true
wait(1)
debounce = true
else
debounce = false
local setTurning = part.PrimaryPart.CFrame * CFrame.Angles(0,math.rad(-90),0)
for i = 0,1,0.1 do
local lerping = part.PrimaryPart.CFrame:Lerp(setTurning,i)
part:SetPrimaryPartCFrame(lerping)
wait()
end
open = false
wait(1)
debounce = true
end
end
end
part.Main.Touched:Connect(onTouch)
math.rad() converts degrees into radians in the argument
##Links
3 comments
The door just wants to be free, free as a bird.
XD
Make sure it's a local script.