With a range of only 800 studs it still has high activity.
You can see cars popping in and out so the range would be even higher. Here’s my code.
local function Heartbeat(DT)
for i, v in pairs(MovingCars) do
if not i.Parent then
MovingCars[i] = nil
continue
end
local Negative = 1
if i.Lane.Value.Parent.Name == "Easy" then
Negative = -1
end
MovingCars[i] -= (i.Lane.Value:GetAttribute("Speed")*DT) * Negative
if Plr.Character and Plr.Character.PrimaryPart then
local Magnitude = (Vector3.new(i.Body.HitBox.Position.X,i.Body.HitBox.Position.Y,MovingCars[i])-Plr.Character.PrimaryPart.Position).Magnitude
if Magnitude <= Range then
i.PrimaryPart.CFrame = CFrame.new(i.PrimaryPart.Position.X,i.PrimaryPart.Position.Y,MovingCars[i]) * CFrame.Angles(math.rad(i.PrimaryPart.Orientation.X),math.rad(i.PrimaryPart.Orientation.Y),math.rad(i.PrimaryPart.Orientation.Z))
end
end
end
end
try using values a bit more like instead of doing part.item.anotheritem.Position.X then part.item.anotheritem.Position.Y. create a variable of part.item.anotheritem.Position then read off that variable. you could do this for the primary part value, the speed attribute, and the current position
local function Heartbeat(DT)
for i, v in pairs(MovingCars) do
if not i.Parent then
MovingCars[i] = nil
continue
end
local Negative = 1
if MovingCars[i]["Lane"].Parent.Name == "Easy" then
Negative = -1
end
MovingCars[i]["Value"] -= (MovingCars[i]["Lane"]:GetAttribute("Speed")*DT) * Negative
if Plr.Character and Plr.Character.PrimaryPart then
local Magnitude = (Vector3.new(MovingCars[i]["X"],MovingCars[i]["Y"],MovingCars[i]["Value"])-Plr.Character.PrimaryPart.Position).Magnitude
if Magnitude <= Range then
i.Parent = workspace.Vehicles
i.PrimaryPart.CFrame = CFrame.new(MovingCars[i]["PrimaryX"],MovingCars[i]["PrimaryY"],MovingCars[i]["Value"]) * CFrame.Angles(math.rad(MovingCars[i]["XAngle"]),math.rad(MovingCars[i]["YAngle"]),math.rad(MovingCars[i]["XAngle"]))
else
i.Parent = game.ReplicatedStorage.VehicleHolder
end
end
end
end
what’s your actual raw fps change compared to before, script activity isn’t too helpful for finding that out try using micro profiler to see each of the events, their names and their usage per frame. press ctrl+f6 then pause it with ctrl+p, way more usable information than script usage and rate.
I am not entirely sure how to interpret the microprofiler, so here’s a screenshot of a microprofiler dump. I also introduced a system where instead of deleting a car when it gets to the other end, it recycles it to stop the rapid cloning.