Why does the value not change?

When the tween in my Open Door Script finishes, it should tick the OpenValue’s boolean, and when the boolean is ticked, the Close Door Script triggers and it unticks the OpenValue boolean when it’s finished.

But, when the Open Door Script is finished, the OpenValue’s boolean doesn’t tick, and therefore, the Close Door Script closes.

I have tried removing the “Value” at the end of the OpenValue’s boolean value.

No errors relating to the script can be found.

Open Door Script

local tweenService = game:GetService("TweenService")
local doorFrame = script.Parent.Parent.DoorFrame
local phantomDoorFrame1 = script.Parent.Parent.PhantomDoorFrame1
local clickDetector = script.Parent.ClickDetector
local openValue = script.Parent.Parent.DoorFrame.OpenValue.Value

local tweeningInformation = TweenInfo.new(
	0.25, -- Duration
	Enum.EasingStyle.Back, -- Easing style
	Enum.EasingDirection.Out, -- Easing Direction
	0, -- Number of repetitions
	false, -- Reverse boolean
	0 -- Delay time between each repetition
)

local partProperties = {
	Position = phantomDoorFrame1.Position;
	Orientation = phantomDoorFrame1.Orientation
}

local tween = tweenService:Create(doorFrame, tweeningInformation, partProperties)

function openDoor()
	if openValue == false then
		tween:Play()
		openValue = true
	end
end

clickDetector.MouseClick:Connect(openDoor)

Close Door Script

local tweenService = game:GetService("TweenService")
local doorFrame = script.Parent.Parent.DoorFrame
local phantomDoorFrame2 = script.Parent.Parent.PhantomDoorFrame2
local openValue = script.Parent.Parent.DoorFrame.OpenValue.Value

local tweeningInformation = TweenInfo.new(
	0.25, -- Duration
	Enum.EasingStyle.Back, -- Easing style
	Enum.EasingDirection.Out, -- Easing Direction
	0, -- Number of repetitions
	false, -- Reverse boolean
	0 -- Delay time between each repetition
)

local partProperties = {
	Position = phantomDoorFrame2.Position;
	Orientation = phantomDoorFrame2.Orientation
}

local tween = tweenService:Create(doorFrame, tweeningInformation, partProperties)

function closeDoor()
	if openValue == true then
		wait(5)
		tween:Play()
		openValue = false
	end
end

closeDoor()

Why dont you do it all in one script? and add a debounce and if it is false that means the door can open if true then the door can be closed

1 Like

I will try that right now, thanks

Now I can’t open it, here is the combined script

local tweenService = game:GetService("TweenService")
local doorFrame = script.Parent.Parent.DoorFrame
local phantomDoorFrame1 = script.Parent.Parent.PhantomDoorFrame1
local phantomDoorFrame2 = script.Parent.Parent.PhantomDoorFrame2
local clickDetector = script.Parent.ClickDetector
local openValue = script.Parent.Parent.DoorFrame.OpenValue.Value

local tweeningInformation1 = TweenInfo.new(
	0.25, -- Duration
	Enum.EasingStyle.Back, -- Easing style
	Enum.EasingDirection.Out, -- Easing Direction
	0, -- Number of repetitions
	false, -- Reverse boolean
	0 -- Delay time between each repetition
)

local partProperties1 = {
	Position = phantomDoorFrame2.Position;
	Orientation = phantomDoorFrame2.Orientation
}

local partProperties2 = {
	Position = phantomDoorFrame1.Position;
	Orientation = phantomDoorFrame1.Orientation
}

local tween1 = tweenService:Create(doorFrame, tweeningInformation1, partProperties1)
local tween2 = tweenService:Create(doorFrame, tweeningInformation1, partProperties2)

function openDoor()
	local debounce = false
	if openValue and debounce == false then
		tween1:Play()
		openValue = true
		debounce = true
		wait(5)
		debounce = false
		if openValue == true and debounce == false then
			tween2:Play()
		end
	end
end

clickDetector.MouseClick:Connect(openDoor)

You are still using openValue. By add a debounce i meant replace the open value with a debounce to check if it is opened or not

1 Like