Tween only works 5/10 times as intended, other times it doesn't do anything at all

I’m trying to tween a clone of a tank model on the client to the position of the real tank model, in an attempt to make the movement look smoother on the client (movement is done on the server so it looks “choppy”). This may not be the best approach so I’m open to suggestions.

local TimeToTween = TweenInfo.new(0.12)
Connection = RunService.Heartbeat:Connect(function()
    local Goal = {}
	Goal.CFrame = TankModel.PrimaryPart.CFrame
    local Tween = TweenService:Create(TankClone.PrimaryPart, TimeToTween, Goal)
    Tween:Play()

    print("Test")

end)

The Heartbeat runs every time without fail (prints “Test”), but tweens only roughly half the time I hit play. I’ve made sure that TankModel and TankClone are never nil as well.
I’m completely stumped and this is making me go nuts.
I’m not sure what other info would be useful so just ask.

i’m pretty sure this is an issue regarding where the script loads too quicker than the primarypart does

That is not the case, as I had already made sure that both TankModel and TankClone were never nil. I tried getting the TankModel every time Heartbeat fired: same results.

The tween keeps replaying so fast it doesn’t move at all because it keeps replaying at the start?

I’m just taking a guess here.

Try the same script but with a while true do loop instead of heartbeat, with maybe a 1 second cooldown, and see if the issue is still there.

I’m willing to try anything at this point. Though I’m heading to bed so I will try it tomorrow.

try adding Wait(3) at the start of the script and run it a few times and see if it works, if it does then some part is loading too slow otherwise, idk

Ok the main issue here is you’re creating a tween and playing it on every heartbeat

I’m going to assume you’re trying to move a goal towards a dynamic object since it’s inside a RunService event

Instead, you should use CFrame:Lerp because tweening objects every frame negates all easing styles and directions and you’re just creating unnecessary overhead while also opening up weird edge cases like this

game:GetService("RunService").Heartbeat:Connect(function(dt)
	Part.CFrame = Part.CFrame:Lerp(Goal.CFrame, 0.12 + dt)
	-- Adding DeltaTime makes sure if there's any lag it takes it into account in Interpolating
end)
1 Like

Sorry for the late reply, but it’s working perfectly fine so far, thank you :smile: Didn’t know / forgot about Lerp