I am trying to create a smooth placement system (like theme park tycoon 2) that glides smoothly to the mouse position. I am using the Lerp() function and it's working except for the fact that it is shaking (or appears to be). I think this has to do with the code updating too fast so when I move my mouse it is trying to move to multiple positions resulting in a shaking effect. I have tried adding waits in places to lower the update time but nothing helps. The script is located in StarterGui later replicated to PlayerGui. It is also a LocalScript. This is a test world and script so nothing else is in the place (other than the baseplate). Here is my code:
-- Creates the part and sets properties
local part = Instance.new("Part")
part.Anchored = true
part.CanCollide = false
part.Parent = game.Workspace
-- Mouse and player
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
-- Position variables that are set below
local PosX, PosY, PosZ
-- Don't worry about this function
local function Snap()
PosX, PosY, PosZ = math.floor(mouse.Hit.X / 2 + 0.5) * 2, 0.5, math.floor(mouse.Hit.Z / 2 + 0.5) * 2 -- Math
return PosX, PosY, PosZ
end
-- Here is where the lerping starts
local function Lerp()
mouse.TargetFilter = part -- Ignores the part
Snap()
-- Lerping
if mouse.Target and mouse.Target.Name == "Baseplate" then
for i = 0, 1, 0.001 do
-- This lerps the part to the mouse position
local mousePos = part.CFrame:Lerp(CFrame.new(PosX, PosY, PosZ), i)
wait(0) -- simple wait
part.CFrame = mousePos -- Sets the CFrame
end
end
end
mouse.Move:Connect(Lerp) -- Event
Thanks for any help in advance!

2 comments
The Move event is being fired each time the mouse moves, resulting in tons of lerps. A debounce may be what you're looking for.
Thanks I will try that!