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.
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.
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)