Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Is there any easier way to tween a model?

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!

1 comment

0

It’s :Connect, not :connect (line 32)

1 answer

✓ Accepted answer

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 comment

1

Thank you!

This discussion is preserved as it was. New answers, comments, and votes are closed.