Chest Opening Tween

Hi guys, i’ve made this script that consent to open a chest for a player, and it works fine, but i want it to tween instead of using “PivotTo” function, the pivot cframe is different from the actual cframe, so i have to use pivot instead of just tweening cframe

Any Help?

local rs = game:GetService("ReplicatedStorage")
local tweenService = game:GetService("TweenService")
local remotes = rs:WaitForChild("Remotes")
local OpenChest = remotes:WaitForChild("ApriChest")

local debounce = false


local Info = TweenInfo.new(
    1,
    Enum.EasingStyle.Elastic,
    Enum.EasingDirection.Out
)



OpenChest.OnClientEvent:Connect(function(chestCover, proximityPrompt)
    if debounce == false then
        debounce = true
        proximityPrompt.Enabled = false
        local currentPivot = chestCover:GetPivot()
        chestCover:PivotTo(currentPivot * CFrame.Angles(0, math.rad(-120),0))
        wait(4)
        chestCover:PivotTo(currentPivot)
        debounce = false
        proximityPrompt.Enabled = true
    end
end)
1 Like

Here’s how you can do it:

local rs = game:GetService("ReplicatedStorage")
local tweenService = game:GetService("TweenService")
local remotes = rs:WaitForChild("Remotes")
local OpenChest = remotes:WaitForChild("ApriChest")

local debounce = false

OpenChest.OnClientEvent:Connect(function(chestCover, proximityPrompt)
    if debounce == false then
        debounce = true
        proximityPrompt.Enabled = false
        local currentPivot = chestCover:GetPivot()
        
        local targetPivotAngle = currentPivot * CFrame.Angles(0, math.rad(-120), 0)
        
        local Info = TweenInfo.new(
            1,
            Enum.EasingStyle.Elastic,
            Enum.EasingDirection.Out
        )
        
        local pivotTween = tweenService:Create(chestCover, Info, {Pivot = targetPivotAngle})
        
        pivotTween:Play()
        
        pivotTween.Completed:Wait()
        
        debounce = false
        proximityPrompt.Enabled = true
        chestCover.Pivot = currentPivot
    end
end)

Adjust the target pivot angle and the tween parameters in the TweenInfo.new function to your needs.

it will get an error on the creation of the tweening “local pivotTween”

Here’s the error:

TweenService:Create no property named ‘Pivot’ for object ‘chestCover’

so you’re still using chatgpt huh?

no i did this code by myself but i was trying to tween it, but i think i can’t tween pivots

im talking about the other guy that answered your topic, dont worry :wink:

I have tried this before and there have been many errors, even if what I tried must’ve theoretically worked.

I would create an invisible “PartA” and “PartB”, the CFrames to set the chest position and orientation to, and an attribute named “CurrentCFrame”, with the value being, obviously, a CFrame.

Then, you can tween the attribute value, and then hook a :GetPropertyChangedSignal() onto that value, to then set the CFrame on the chest.

Kind of unnecessary and complicated, but it works-

Unfortunately you can’t set Pivot directly via tween. It’s not on the list of supported properties for Tween.

I ended up using the solution here, which uses lerp instead of tweenservice: Is there any way i can tween PivotTo? - #8 by Forummer