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

How to use tweenservice for the same model in different places?

Hey there, so I'm not very familiar with using tweenservice for parts, I have a basic understanding of it so far Currently, this is what I have for my door that I'm creating, as you can see the position is copied and pasted from what I want the outcome to be, But if I were to say duplicate this door and put it elsewhere I would have to copy and paste the information into the script again, is there a way to do it so I don't have to do this?

local TweenService = game:GetService("TweenService")

local part = script.Parent

local goal = {}

goal.Position =  Vector3.new(-74.8, 3.45, 42)
goal.Color = Color3.new(0,1,0)
goal.CFrame = CFrame.new()
goal.Orientation = Vector3.new(0,90,0)
local tweeninfo = TweenInfo.new(3, Enum.EasingStyle.Bounce)

local tween = TweenService:Create(part, tweeninfo, goal)

tween:Play()

2 answers

✓ Accepted answer

You could. Instead of using Position and Orientation, you can use CFrame. CFrame contains 2 primary Vector3s, position and lookVector. If you want something to be repositioned and to face somewhere, you'd set it's CFrame to CFrame.new(position, lookVector);

Now you're probably wondering how you can make this work for any model? Well, the easiest way is by multiplying CFrames. You would make it's Goal CFrame be it's original CFrame multiplied by CFrame.new(x, y, z). Then, you can rotate it by multiplying by CFrame.Angles(radianX, radianY, radianZ);

Just remember that CFrame.Angles accepts radians only. To convert between radians and degrees, you'd use math.rad(xRadians), and it'll convert xRadians to degrees.

[ LINKS ]

{ CFrame Math Operations } - https://developer.roblox.com/en-us/articles/CFrame-Math-Operations { Understanding basic CFrame concepts } - https://developer.roblox.com/zh-cn/articles/Understanding-CFrame { What are CFrames? [Includes CFrame.Angles()] } - https://developer.roblox.com/ko-kr/api-reference/datatype/CFrame

You could use a Loop to gather all the parts that are considered "Door"... For Example :

for _, obj in pairs(workspace:GetDescendants()) do
	if obj.Name == "Door" then

		--//Tween stuff here		

	end
end

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