Tweening model dosent move other parts

You can write your topic however you want, but you need to answer these questions:

  1. I am trying to make a truck that when tweened moves with boxes

  2. When i tween truck it moves but the boxes inside doesn’t
    BEFORE


    AFTER

Inside workspace
image_2022-12-29_132418381

Code

local TweenService = game:GetService("TweenService")

local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
local Model_X = script.Parent.Position.X
local Model_Y = script.Parent.Position.Y
local Model_Z = script.Parent.Position.Z

local Model_Orientation_X = script.Parent.Orientation.X
local Model_Orientation_Y = script.Parent.Orientation.Y
local Model_Orientation_Z = script.Parent.Orientation.Z

local function Move_Truck()
	if Model_Orientation_Y == 90 then
		Model_Z = Model_Z + 30
	end
	if Model_Orientation_Y == -90 then
		Model_Z = Model_Z - 30
	end
	if Model_Orientation_Y == -180 then
		Model_X = Model_X + 30
	end
	if Model_Orientation_Y == 180 then
		Model_X = Model_X - 30
	end                                             --this part used to know in what direction the truck will be

	local tween = TweenService:Create(script.Parent, tweenInfo, {Position = Vector3.new(Model_X,Model_Y,Model_Z)})
	tween:Play()
end

Move_Truck()
  1. I have read before other solutions how to tween models but I haven’t quiet understand them since non of them worked for me.

It doesn’t tween the boxes because you did not tween them

local function tweenModel(model: Model, tweenInfo, goal)
   for _, v in model:GetDescendants() do
      if v:IsA("BasePart") then
         local tween = TweenService:Create(v, tweenInfo, goal)
	tween:Play()
      end
   end
end

Weld the boxes to the primary part of the truck model, to make them move along with the truck while tweening, and I suggest to use the CFrame * CFrame.new(0,0,-30) to tween the truck

In this way you dont need to check the orientation of the truck, it will always move forward relative of the part orientation (front) by 30 studs.

Any part welded to the truck will move with it, due to using CFrame when tweening

local TweenService = game:GetService("TweenService")

local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)

local function Move_Truck()
	local tween = TweenService:Create(script.Parent, tweenInfo, {CFrame = script.Parent.CFrame * CFrame.new(0,0,-30) })
	tween:Play()
end

wait(5)
Move_Truck()
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.