Change cframe door direction

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)

Can you provide us with a video?

You’re having issues regarding these values. Did you try experimenting with them further (e.g.: moving them around, seeing what happens when you do something specific to them)?

Not really no, I had figured it had been an issue with the top frame portion, but this makes sense as well.

1 Like

Hello. This is the answer to your question, but a quick tip for you is to play the animations on the clients. When you play them on the server, they look more choppy, slow down your game and players with an internet connection that is not up to par will have the animations ‘lag’ for them.

Well, it was smooth before, just not after I input negative numbers to try and change direction, but that is a good idea nevertheless.

Try using CFrame:Lerp() . It might fix your problems!

Where would I add this in the script?

First off, get rid of your tweening stuff. Then change it all to CFrame:lerp() .