I am making a horror game right now and I am not sure how to make a 2 way open door.
I am trying to make it open the oposite side that the player is.
Here is my script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local TweenService = game:GetService("TweenService")
local Assets = script.Parent.Assets
local ProximityPromt = Assets:FindFirstChild("DoorKnob").Detector
local Hinges = script.Parent.Hinges
local HingePart = Hinges.HingePart
local MainDoor = script.Parent.Assets.Door
local Remotes = ReplicatedStorage.Remotes
local InteractionTextRemote = Remotes.InteractionText
local DoorSound = script.Parent.Assets.DoorSound
local DoorOpenGoal = { }
DoorOpenGoal.CFrame = HingePart.CFrame * CFrame.Angles(0,math.rad(90),0)
local DoorCloseGoal = { }
DoorCloseGoal.CFrame = HingePart.CFrame * CFrame.Angles(0,0,0)
local Speed = TweenInfo.new(1)
local TweenOpen = TweenService:Create(HingePart,Speed, DoorOpenGoal)
local TweenClose = TweenService:Create(HingePart,Speed, DoorCloseGoal)
--FUNCTIONS
function OPEN_CLOSE_Door()
--OPENARGUMENT
if ProximityPromt.ActionText == "Open" then
TweenOpen:Play()
DoorSound:Play()
MainDoor.CanCollide = false
ProximityPromt.Enabled = false
ProximityPromt.ActionText = "Close"
TweenOpen.Completed:Connect(function()
ProximityPromt.Enabled = true
MainDoor.CanCollide = true
end)
return
end
--CLOSEARGUMENT
if ProximityPromt.ActionText == "Close" then
TweenClose:Play()
DoorSound:Play()
MainDoor.CanCollide = false
ProximityPromt.Enabled = false
ProximityPromt.ActionText = "Open"
TweenClose.Completed:Connect(function()
ProximityPromt.Enabled = true
MainDoor.CanCollide = true
end)
return
end
end
--PROMT DETECTION
ProximityPromt.Triggered:Connect(function(Owner)
OPEN_CLOSE_Door()
end)```