I've been having a problem with my script that the CFrame animations that it uses always tend to lag and it looks chopped up at times. I've seen other people's scripts where they look much smoother, but I don't know how to make it like that. I'm using RunService.Heartbeat and CFrame:Lerp for my animations, but I don't know if this is the best idea. I'm using the following code below.
local function MoveTabs(plr)
local tabs = Core.Admins[plr.UserId].Data.Tabs
local r
Core.Services["RunService"].Heartbeat:Connect(function()
local torso = plr.Character:FindFirstChild("HumanoidRootPart")
if not torso then
return
else
if #tabs ~= 0 then
r = 3 + #tabs
local x = 1
for i = 0, (360/#tabs)*#tabs, (360/#tabs) do
if x > #tabs then
x = 1
end
local cf = CFrame.new(torso.Position) * CFrame.new(r * math.cos(math.rad(i)), 0, r * math.sin(math.rad(i)))
local newCF = CFrame.new(cf.p, torso.Position)
tabs[x].CFrame = tabs[x].CFrame:Lerp(newCF, .05)
x = x + 1
end
else
r = 0
end
end
end)
end
I would really appreciate if someone could explain to me a better way to accomplish this, as the bricks involved with this movement tend to look really laggy in larger servers (I'm running it in script builder). Help would be very appreciated, thank you.
[Edit]: I've heard of using TweenService to make smoother animations, but I don't know how that would work especially in a loop like this.

1 comment
i mean, you can use heartbeat and replicate the for loop with it