Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why isn't a part moving properly between two parts with Heartbeat?

Hi. I'm using Lerp inside a Heartbeat function to move one part from one point to another. This works perfectly when I'm trying to move the part to only one point, but as soon as it starts moving to a second point, it starts stuttering and stops in the middle where it stutters even more back and forth.

This is probably explained much better in a gif, so here's a link

Here's the code

local RunService = game:GetService("RunService")

local partA = workspace.A --point A
local partB = workspace.B --point B
local partC = workspace.C --moving part

local speed = 2

RunService.Heartbeat:Connect(function(deltaTime)
	local deltaSpeed = deltaTime * speed
	
	local CFrameLerpA = partC.CFrame:Lerp(partA.CFrame, deltaSpeed)
	partC.CFrame = CFrameLerpA
	wait(5)
	local CFrameLerpB = partC.CFrame:Lerp(partB.CFrame, deltaSpeed)
	partC.CFrame = CFrameLerpB
end)

1 answer

After you change PartC's CFrame to CframeLerpB it goes straight into changing the CFrame to CFrameLerpA as it is constantly running that block of code

Consider adding a wait after line 16 "partC.CFrame = CFrameLerpB"

2 comments

0

Sorry for the late reply. Just tried that, and nothing changed, it still stutters.

0

Alright, fixed the problem. Thank you regardless, though.

This discussion is preserved as it was. New answers, comments, and votes are closed.