Help with tweening position

I tried to make a tween that resizes to one side. Though it did work, I somehow managed to find some bugs that I can’t seem to fix.

Here is the code:

RightCDetect.ClickDetector.MouseClick:Connect(function()
    local ClosedSize, OpenSize = RCurtain:GetAttribute("ClosedSize"), RCurtain:GetAttribute("OpenSize")
    local OpenAnim = TweenService:Create(RCurtain, TI, {Size = OpenSize, CFrame = RCurtain.CFrame * CFrame.new(2.125 / 2, 0, 0)})
    local CloseAnim = TweenService:Create(RCurtain, TI, {Size = ClosedSize, CFrame = RCurtain.CFrame * CFrame.new(-2.125 / 2, 0, 0)})
    
    Folder.Sound:Play()
    if RCurtain:GetAttribute("Open") then -- // Close
        CloseAnim:Play()
        RCurtain:SetAttribute("Open", false)
    else -- // Open
        OpenAnim:Play()
        RCurtain:SetAttribute("Open", true)
    end
end)

And this is the bug. I assume it was because I clicked on it multiple times, not giving the tweens time to actually finish and they clash with each other.
https://gyazo.com/9571cad745dd4a21bd158d90a474b966

Rather than creating the tweens after the click, create the tweens beforehand then play them. What’s happening is the tweens are being created in a way that assumes the curtain is always in the open state, but since the curtain can also be closed or half-closed when interacted with, the curtain creates tweens that are based on its current position and size rather than what it would be by default.

1 Like