I has problem streaming part with obby generator
First when play game of long obby without laggy and camera turn around make slow down with too many part and laggy its see picture:
I’ve actually been working on a game of my own with a similar concept to this, and in that project I generate each level individually, one at a time. The player steps on a blue pad and it generates the first level, as well as a checkpoint at the end. Each checkpoint then generates the next level.
Behind the player, old levels gradually degenerate in order to reduce lag.
I don’t know if this would work for your specific game, but if part lag is the issue, maybe the best solution is to just have less parts all at once.
local Current = workspace.Obbies
local Obbies = game.ReplicatedStorage.Obbies:GetChildren() -- getting the current obbies
local StartingPos = CFrame.new(-23, 99.5, 0) -- where the 1st part will be.
local MaxObbies = math.huge -- the obbies it generates(math.huge = inf)
local Rng = Random.new() -- rng for generating the obbies
wait(1)
local function Add(Obby) -- function for adding the obbies
local NewName = #Current:GetChildren() + 1
Obby.Name = string.format("%.f", NewName) -- names the obby
if Obby.Name == "1" then -- if this is the first obby generated
Obby:PivotTo(StartingPos) -- moves the obby into the starting pos
Obby.Parent = Current -- parents the obby so we can see it
else -- if it isn't the first obby generated
local LatestObby = Current:FindFirstChild(string.format("%.f", #Current:GetChildren())) -- gets the latest obby generated
if LatestObby then
Obby:PivotTo(LatestObby.End.CFrame) -- moves the obby to the latest obby's end part cframe
Obby.Parent = Current
end
end
end
for i = 1, MaxObbies, 1 do -- this will repeat the code between the for and the end based on the max obbies value
local RandomNum = Rng:NextInteger(1, #Obbies) -- gets a random integer(whole number, no decimals)
local Obby = Obbies[RandomNum]:Clone() -- gets an obby inside the obbies folder with the random number
if Obby then
Add(Obby) -- adds the obby
end
task.wait() -- not to crash the game
end
use a client sided :Destroy() on models outside of a radius, or once the workspace has x models delete the oldest one, using a list to keep track of the models. Use .ChildAdded on the workspace and add the model to the end of a list, and once that list’s length is greater than 10 for example, destroy the oldest model and remove it from the list. iirc streaming won’t remove instances until some cap is filled up but I’ve never used it.
I see you’re having problems with not only the Obby but with game optimization. Keep in mind that generating infinite obbies/stages (Which basically makes sense) will lag your game alot. Mainly if the Stages/Obbies contain alot of parts. For that, I recommend you taking a look at Janitor Module & Maid Module for storing Instances/Events (Or Connections), Changing your game’s PhysicsSteppingMethod to “Adaptive” (Can be done via Workspace > Behavior > PhysicsSteppingMethod > Adaptive)
And the most important part is to not make the number of Obbies/Stage infinite, Maybe try making it something around 100 ~ 1000 If you want alot of Stages.