How to move objects smoothly using tween service?

Hey there, I want to move this pet smoothly, can anyone help me?

here is the script

local tweenService = game:GetService("TweenService")
local char = script.Parent.Parent.Parent
local hum = char:FindFirstChild("Humanoid")
local HumanoidRootPart = char:FindFirstChild("HumanoidRootPart")
local pet = script.Parent



while wait() do
	local goal = {}
	goal.CFrame = HumanoidRootPart.CFrame + Vector3.new(3,1,3)
	
	local tweenInfo = TweenInfo.new(0.01, Enum.EasingStyle.Linear, Enum.EasingDirection.In,0,false,0.01)
	print(pet.CFrame)
	local tween = tweenService:Create(pet,tweenInfo,goal)
	print(tween)
	tween:Play()
end 
		

2 Likes

Set the tween to play longer:

while wait(1) do
	local goal = {}
	goal.CFrame = HumanoidRootPart.CFrame + Vector3.new(3,1,3)
	
	local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut) 
        --[[ I've changed these properties to make it look smoother (Linear to Sine, In to InOut), 
             and changed the time from 0.01 to 1
        --]]
	print(pet.CFrame)
	local tween = tweenService:Create(pet,tweenInfo,goal)
	print(tween)
	tween:Play()
end 

and it should feel smooth.

1 Like

It moving very slow now. I want it move at the same speed, but smoothly

Simply change the number 1 in these two lines to a smaller value and it should be better:

while wait(1) do
local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut) 

Nope, it still not smooth. I made it 0.5 and it was slow, did 0.01 and it wasnt smooth

Can I see your current script? And possibly take a video to see the progress (it helps!).

here

local tweenService = game:GetService("TweenService")
local char = script.Parent.Parent.Parent
local hum = char:FindFirstChild("Humanoid")
local HumanoidRootPart = char:FindFirstChild("HumanoidRootPart")
local pet = script.Parent



while wait() do
	local goal = {}
	goal.CFrame = HumanoidRootPart.CFrame + Vector3.new(3,1,3)
	wait(0.01)
	local tweenInfo = TweenInfo.new(0.11, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut,-30,false,0.01) 
        --[[ I've changed these properties to make it look smoother (Linear to Sine, In to InOut), 
             and changed the time from 0.01 to 1
        --]]
	print(pet.CFrame)
	local tween = tweenService:Create(pet,tweenInfo,goal)
	print(tween)
	tween:Play()
end 

You have to make the wait time as fast as the tween time, and try playing around with the easing styles and directions.

Yeah basically the tweens are playing before the tween finishes playing, and that leads to the choppiness. ^^

do u know any fix? for the tween?

It’s just like TOP said you have to make the wait time the same as the tween time.

I did but it still not smooth

local goal = {}
	goal.CFrame = HumanoidRootPart.CFrame + Vector3.new(3,1,3)
	wait(0.05)
	local tweenInfo = TweenInfo.new(0.05, Enum.EasingStyle.Back, Enum.EasingDirection.InOut) 
        --[[ I've changed these properties to make it look smoother (Linear to Sine, In to InOut), 
             and changed the time from 0.01 to 1
        --]]
	print(pet.CFrame)
	local tween = tweenService:Create(pet,tweenInfo,goal)
	print(tween)
	tween:Play()

take a look above I did what u said ^

Don’t use TweenService, use BodyMovers, I recommend a BodyPosition that is relative to the character.

1 Like

Only if you want physics to apply to the Pet. If it gets stuck you’ll need to teleport it if the pet gets too far away.

As a tip for tween service you should be calculating the time based on distance and speed. This is so the pet moves consistently regardless of distance if you continue to use TweenService.
Time = Distance/Speed
Distance will be the magnitude between the player and pet.
Speed you’ll have to tweak until you get the value you want.

2 Likes

BodyPosition can be used despite gravity, and if getting stuck is a real problem then it doesn’t hurt to turn collisions off for the pet because no one should be interacting with it anyway if its considered cosmetic of course.

1 Like

It seems like you are doing it on the server, which can cause some latency, try doing it in a local script instead(client sided). And like others suggested, try using body movers if that doesn’t work.

3 Likes

Ok if I do it in the client side, so do I change the position in the server