Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Is there any easier way to tween a model?

Asked by 5 years ago

In short, I was working on a sliding door a while ago. I couldn't for the life of me get the whole model (The door) to move using one script and so I had to tween each individual part and have them all connect to a single click detector. This meant (due to my lack of scripting knowledge most likely) that I had to write a script for every part and tween the parent. This totaled to 9 scripts per door. I know, awful. I was wondering if there was a more effective way of doing this using one script.

This is the script I inserted into each part.

opened = false
local TweenService = game:GetService("TweenService")
local part = script.Parent

local Info = TweenInfo.new(
    2,
    Enum.EasingStyle.Quad,
    Enum.EasingDirection.InOut,
    0,
    false,
    0
)

local open = {CFrame = part.CFrame + part.CFrame.lookVector * -4.2}
local close = {CFrame = part.CFrame }

local tweenOpen = TweenService:Create(part,Info,open)
local tweenClose = TweenService:Create(part,Info,close)

function toggle()
    if opened == false
        then tweenOpen:Play()
        opened = true

    else
        tweenClose:Play()
        opened = false

    end
end

part.Parent.Paper.ClickDetector.MouseClick:connect(toggle)

Any help would be greatly appreciated! Thank you!

0
It’s :Connect, not :connect (line 32) User#19524 175 — 5y

1 answer

Log in to vote
0
Answered by
jtefurd 50
5 years ago

I've actually just finished writing code to tween models' CFrame. There's no easy way like just using one of Roblox's prebuilt methods. However on the dev forum, they suggested a simple solution by using a CFrameValue, :SetPrimaryPartCFrame(), and detecting when the CFrameValue's Value property changed. Check it out, you'll find what you're looking for.

https://devforum.roblox.com/t/how-do-i-use-tweenservice-with-setprimarypartcframe/63466/6

1
Thank you! moondragon333 8 — 5y
Ad

Answer this question