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

How do I tween multiple parts?

So I have model that I'm trying to tween but I can't seem to get it working. I tried looping through the model and doing local example = game.Workspace.example.PrimaryPart but that didn't work either. I'm at a lost for what to do right now so help is appreciated.

local on = false

local TweenService = game:GetService("TweenService")
local TweeningInformation = TweenInfo.new(
	8,
	Enum.EasingStyle.Bounce,
	Enum.EasingDirection.Out,
	0,
	false,
	0
)

local goUp = {CFrame = CFrame.new(-217.408, 2.934, 12.847)}
local goDown = {CFrame = CFrame.new(-217.408, -31.094, 12.847)}

script.Parent.ClickDetector.MouseClick:Connect(function()
	if on == false then
		for _,v in pairs(game.Workspace.Present:GetChildren()()) do
			local tweenUp = TweenService:Create(v,TweeningInformation,goUp)
			tweenUp:Play()
		end
		on = true
	else
			for _,v in pairs(game.Workspace.Present:GetChildren()) do
				local tweenDown = TweenService:Create(v,TweeningInformation,goDown)
				tweenDown:Play()
			end
			on = false
	end
end)

1 answer

✓ Accepted answer

Instead of changing each individual part, you can set the primarypart cframe of the model. Step 1) Setting the Primary Part Inside the properties tab when you click your model, set your primarypart to 1 part, preferably an invisible part that is not collidable. Make sure its size is around the whole size of your present, like a hitbox.

Step 2) Getting the part to go up and down Make sure your whole model is anchored. For this I'm going CFrame:Lerp()

local present = workspace:WaitForChild('Present')

local targetcframe = INSERT_CFRAME_HERE

for i = 0,1,.01 do
	local cf = present.PrimaryPart.CFrame:Lerp(targetcframe,i)
	present:SetPrimaryPartCFrame(cf)
	wait(.01)
end

1 comment

0

How do I change the orientation(rotation) though?

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