How to tween a model

i want to tween a model in bezier Curve but i cant tween the model because it doesnt have CFrames

i searched it up on the dev forum but couldnt find any fixes to my problem

here is the code that im trying to do it on

im also using a bezier module script to tween it


local BezierTween = require(game.ServerScriptService.BezierTweens)
					local Waypoints = BezierTween.Waypoints
					local P0, P1, P2 = workspace.Points.PointA, workspace.Points.PointC, workspace.Points.PointB
					
					waypoints = Waypoints.new(P0, P1, P2)
					
					local tween = BezierTween.Create(primaryPart, {
						Waypoints = waypoints,
						EasingStyle = Enum.EasingStyle.Sine,
						EasingDirection = Enum.EasingDirection.In,
						Time = 5,
					})
					
					
					
					tween:Play()
					tween.Completed:Wait()

You can set the PrimaryPart of the model and use that as the anchor point for the tween

sorry i forgot to mention but ive already tried welding other parts to the primaryPart and only anchoring the primary part it didnt work

Have you tried tweening a fake part and doing :PivotTo() on the character model every frame with the part’s CFrame?

no i havent tried that yet how can i do that?

Tweening a model directly can be tricky because models don’t have a direct CFrame property. Instead, you need to tween the CFrame of the model’s primary part and then update the positions of all other parts relative to the primary part.

Try this script

local BezierTween = require(game.ServerScriptService.BezierTweens)
local Waypoints = BezierTween.Waypoints

-- Define your points for the Bezier curve
local P0, P1, P2 = workspace.Points.PointA, workspace.Points.PointC, workspace.Points.PointB
local waypoints = Waypoints.new(P0, P1, P2)

-- Reference to your model and its PrimaryPart
local model = workspace.YourModelName -- Replace with your model's name
local primaryPart = model.PrimaryPart

-- Tween the PrimaryPart along the Bezier curve
local tween = BezierTween.Create(primaryPart, {
    Waypoints = waypoints,
    EasingStyle = Enum.EasingStyle.Sine,
    EasingDirection = Enum.EasingDirection.In,
    Time = 5,
})

-- Function to update the whole model based on the PrimaryPart
local function updateModelPosition()
    local cframe = primaryPart.CFrame
    for _, part in ipairs(model:GetChildren()) do
        if part:IsA("BasePart") and part ~= primaryPart then
            -- Update each part's position relative to the PrimaryPart
            part.CFrame = cframe * primaryPart.CFrame:ToObjectSpace(part.CFrame)
        end
    end
end

-- Connect the update function to the tween
tween.Changed:Connect(updateModelPosition)

-- Start the tween
tween:Play()
tween.Completed:Wait()

ive changed the code and it gives error in the output:

attempt to index nil with ‘Connect’

also ive fixed the problem already still thanks for helping it was a problem with the model ive got it to work with another model

1 Like

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