Tween curtain not working

Hi,

I’m working on a curtain system that expands from the left side. However, despite adjusting the right Z axis, it expands from both left and right, which is not what I want since curtains don’t behave like that.

I’m unsure about the best approach to fix this. Should I implement a tweening system to ensure it moves to the left while resizing?

Here’s my script:

local TweenService = game:GetService("TweenService")
local SoundService = game:GetService("SoundService")

local Part = script.Parent
local prompt = Part.ProximityPrompt

-- Define open and close positions for the door
local Open = {
	Size = Vector3.new(1.087, 12.29, 3.925),
}

local Close = {
	Size = Vector3.new(1.087, 12.29, 5.444)
}

local tweeninfo = TweenInfo.new(0.5, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out)

-- Create tweens for opening and closing the door
local tweenOpen = TweenService:Create(Part, tweeninfo, Open)
local tweenClose = TweenService:Create(Part, tweeninfo, Close)

-- Define sound effects
local openSound = Instance.new("Sound")
openSound.SoundId = "rbxassetid://16550161811"
openSound.Parent = script.Parent

local closeSound = Instance.new("Sound")
closeSound.SoundId = "rbxassetid://16550161811"
closeSound.Parent = script.Parent

local isOpen = false

-- Function to handle opening the door
local function OpenDoor()
	if not isOpen then
		isOpen = true
		tweenOpen:Play()
		openSound:Play()
	end
end

-- Function to handle closing the door
local function CloseDoor()
	if isOpen then
		isOpen = false
		tweenClose:Play()
		closeSound:Play()
	end
end

-- Connect the function to the proximity prompt's triggered event
prompt.Triggered:Connect(function()
	if isOpen then
		CloseDoor()
	else
		OpenDoor()
	end
end)

You could try splitting up the part into (Left-side, Right-side) because it seems that the code here was originally meant for a door. So splitting up the curtain into two sides will allow you to tween what side you want.

2 Likes

Hi,

I copied the script from my door model and tweaked it around, but even with the CloseDoor and OpenDoor function it should work on a curtain so renaming it doesn’t change anything.

I messed around with the script and came up with the idea to move the curtain left while it resizes to give it the illusion that it’s resizing from the left face. Here’s what I have right now, but for some reason once the curtain is closed, it won’t open again with the proximity prompt:


local TweenService = game:GetService("TweenService")
local SoundService = game:GetService("SoundService")

local Part = script.Parent
local prompt = Part.ProximityPrompt

-- Define open and close properties for curtain
local Open = {
	Size = Vector3.new(1.087, 12.29, 3.925),
	Position = Vector3.new(-30.872, 13.745, -34.797),
}

local Close = {
	Size = Vector3.new(1.087, 12.29, 5.444),
	Position = Vector3.new(-30.872, 13.745, -34.696),
}

local tweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out)

-- Tween to resize and move curtain
local tween = TweenService:Create(Part, tweenInfo, {
	Size = Close.Size,
	Position = Close.Position,
})

-- Sound
local openSound = Instance.new("Sound")
openSound.SoundId = "rbxassetid://16550161811"
openSound.Parent = script.Parent

local closeSound = Instance.new("Sound")
closeSound.SoundId = "rbxassetid://16550161811"
closeSound.Parent = script.Parent

local isOpen = false

-- Function to handle opening and closing curtain
local function ToggleCurtain()
	if isOpen then
		isOpen = false
		tween:Play(Open)
		closeSound:Play()
	else
		isOpen = true
		tween:Play(Close)
		openSound:Play()
	end
end

-- Connects the function to the proximity prompt's triggered event
prompt.Triggered:Connect(function()
	ToggleCurtain()
end)
1 Like

Try this:

local TweenService = game:GetService("TweenService")
local SoundService = game:GetService("SoundService")

local Part = script.Parent
local prompt = Part.ProximityPrompt

-- Define open and close properties for curtain
local Open = {
	Size = Vector3.new(1.087, 12.29, 3.925),
	Position = Vector3.new(-30.872, 13.745, -34.797),
}

local Close = {
	Size = Vector3.new(1.087, 12.29, 5.444),
	Position = Vector3.new(-30.872, 13.745, -34.696),
}

local tweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out)

-- Tween to resize and move curtain
local tween = TweenService:Create(Part, tweenInfo, {
	Size = Close.Size,
	Position = Close.Position,
})

-- Sound
local openSound = Instance.new("Sound")
openSound.SoundId = "rbxassetid://16550161811"
openSound.Parent = script.Parent

local closeSound = Instance.new("Sound")
closeSound.SoundId = "rbxassetid://16550161811"
closeSound.Parent = script.Parent

local isOpen = false

-- Function to handle opening and closing curtain
local function ToggleCurtain()
	if isOpen == true then
		isOpen = false
		tween:Play(Open)
		closeSound:Play()
	else
		isOpen = true
		tween:Play(Close)
		openSound:Play()
	end
end

-- Connects the function to the proximity prompt's triggered event
prompt.Triggered:Connect(function()
	ToggleCurtain()
end)
1 Like

Still nothing :confused:

When I interact with the proximity prompt for the first time it closes the curtain, but then when I want to open the curtain and interact with the prompt again, it does not do anything, it simply won’t budge.

1 Like

Try this one:

local TweenService = game:GetService("TweenService")
local SoundService = game:GetService("SoundService")

local Part = script.Parent
local prompt = Part.ProximityPrompt

-- Define open and close properties for curtain
local Open = {
	Size = Vector3.new(1.087, 12.29, 3.925),
	Position = Vector3.new(-30.872, 13.745, -34.797),
}

local Close = {
	Size = Vector3.new(1.087, 12.29, 5.444),
	Position = Vector3.new(-30.872, 13.745, -34.696),
}

local tweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out)

-- Sound
local openSound = Instance.new("Sound")
openSound.SoundId = "rbxassetid://16550161811"
openSound.Parent = script.Parent

local closeSound = Instance.new("Sound")
closeSound.SoundId = "rbxassetid://16550161811"
closeSound.Parent = script.Parent

local isOpen = false

-- Function to handle opening and closing curtain
local function ToggleCurtain()
	if isOpen == true then
local tween = TweenService:Create(Part, tweenInfo, Close)
		isOpen = false
		closeSound:Play()
		tween:Play()
repeat task.wait() until (tween.PlaybackState == Enum.PlaybackState.Completed)
tween:Destroy()
	else
local tween = TweenService:Create(Part, tweenInfo, Open)
		isOpen = true
		openSound:Play()
tween:Play()
repeat task.wait() until (tween.PlaybackState == Enum.PlaybackState.Completed)
tween:Destroy()
	end
end

-- Connects the function to the proximity prompt's triggered event
prompt.Triggered:Connect(function()
	ToggleCurtain()
end)

That still doesn’t get it right, it seems to move the curtain to the new position first and then activate the size sequence. It’s supposed to do it together at once. :confused:

This seems a lot harder than I expected.

1 Like

Can you show video? :thinking:

1 Like

What I do is that I tween the Position too so it looks like the size tween is tweening only one side.

Make the curtain move to the left and it will work

But doesn’t it need to unfold? If I use size to unfold it looks like it’s actually unfolding.

Well the unfold effect is still present, it just look like you are unfolding the curtain to a single side