So I have a script for some doors, problem is no matter what I do the direction that the door opens doesn’t change. I tried setting the values to negative, but that just made it so that the animation no longer tweened, just changed position.
Script:
local tweenService = game:GetService("TweenService")
local event = Instance.new("BindableEvent")
local Door = script.Parent.Door
local DoorMain = Door.MainDoor
local TweenedCompleted = "N/A"
local DoorStatus = "Closed"
local Debounce = false
local ProximityPrompt = script.Parent.KeycardReader1.ProximityPrompt
local clearance = {
["Staff-Card"] = true,
["Stolen Card"] = false,
["SD"] = true,
["REDACTED"] = true,
["Omni"] = true,
["MTF"] = true,
["L5"] = true,
["L4"] = true,
["L3"] = true,
["L2"] = true,
["L1"] = true
}
local function tweenModel(model, cframe, time)
local cframeValue = Instance.new("CFrameValue")
cframeValue.Value = model:GetPrimaryPartCFrame()
cframeValue:GetPropertyChangedSignal("Value"):connect(function()
model:SetPrimaryPartCFrame(cframeValue.Value)
end)
local info = TweenInfo.new(time, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)
local tween = tweenService:Create(cframeValue, info, {Value = cframe})
tween:Play()
tween.Completed:connect(function()
cframeValue:Destroy()
end)
end
local cframes = {
orig = Door.Center.CFrame,
tgp = script.Parent.ToGoPos.CFrame,
horig = Door.Handle.Center.CFrame,
htgp = Door.Handle.ToGoPos.CFrame
}
local function Open()
tweenModel(Door.Handle, cframes.htgp, 0.2)
wait(.2)
tweenModel(Door, cframes.tgp, 0.7)
end
local function Close()
tweenModel(Door, cframes.orig, 0.7)
wait(.61)
DoorMain.Bang:Play()
wait(.9)
tweenModel(Door.Handle, cframes.horig, 0.2)
end
--//Toggle event//--
ProximityPrompt.Triggered:Connect(function(player)
local IsInBackpack = false
for index, v in pairs(clearance) do
if player.Character:FindFirstChild(index) or player.Backpack:FindFirstChild(index) then
IsInBackpack = true
end
end
if IsInBackpack and Debounce == false then
Debounce = true
DoorMain.Open:Play()
script.Parent.AccessGranted:play()
script.Parent.Light1.BrickColor = BrickColor.new("Lime green")
ProximityPrompt.Enabled = false
Open()
wait(1)
DoorStatus = "Opened"
wait(3)
DoorMain.Close:Play()
script.Parent.Light1.BrickColor = BrickColor.new("Lily white")
ProximityPrompt.Enabled = true
Close()
DoorStatus = "Closed"
Debounce = false
else
script.Parent.AccessDenied:play()
script.Parent.Light1.BrickColor = BrickColor.new("Really red")
ProximityPrompt.Enabled = false
wait(1)
script.Parent.Light1.BrickColor = BrickColor.new("Lily white")
ProximityPrompt.Enabled = true
end
end)