Render system for UI is doesnt help lag

I dont know how MIDI files can be ran without lag in other software but in roblox, its heavy on lag.

basically when i load midi files into the game, over 10k ImageButtons are created

and the the render system would become redundant as i might as well loop through all to see if the playhead collides with each note.

In every ImageButton(note)
[runs when it gets created

local mod = require(game.ReplicatedStorage.RENDERMODULE)
local tbl = mod.getRecipes()
table.insert(tbl,script.Parent)

in the touch script:

local RunService = game:GetService("RunService")
local Collectionservice = game:GetService("CollectionService")
local play = game.ReplicatedStorage.Remotes.Playsound2
local stop = game.ReplicatedStorage.Remotes.StopSound
local mod = require(game.ReplicatedStorage.RENDERMODULE)
local tbl = mod.getRecipes()

function OnTouch(b)
	local MusicianID = b.Parent.Parent.Parent.Parent.Parent.Parent.ID.Value
	local a = b.Parent.Parent.Parent.Parent.DragableFrame
	local posx = b.AbsolutePosition.X
	if a.AbsolutePosition.X >= b.AbsolutePosition.X and a.AbsolutePosition.X <= b.AbsolutePosition.X+b.AbsoluteSize.X then

		if b.UIStroke.Enabled == true then return end
		local velocity = b.assets.Velocity.Value
		play:FireServer(b.Parent.Key.Value,b.Parent.Octave.Value,b.Parent.Pitch.Value,b.AbsolutePosition.X,b.AbsolutePosition.Y,MusicianID,velocity,b.Name)
		b.UIStroke.Enabled = true
	else
		b.UIStroke.Enabled = false
		stop:FireServer(b.Name)
	end

end

local function isInScreen(b)
	local pos = b.AbsolutePosition
	return pos.X  <= b.Parent.Parent.Parent.Parent.Parent.AbsoluteSize.X and pos.X >= 0
end
local RATE_PER_SECOND = 2

function tag(d)
	if isInScreen(d) then
		Collectionservice:AddTag(d,"regions")
		d.Visible = true
	else
		if Collectionservice:HasTag(d,"Selected") then return end
		Collectionservice:RemoveTag(d,"regions")
		stop:FireServer(d.Name)
		d.Visible = false
	end
end

RunService.RenderStepped:Connect(function(step)
	local increment = RATE_PER_SECOND * step
	task.wait(increment)
	for  k=1, #tbl do local b = tbl[k]
		--if not Collectionservice:HasTag(b,"regions") then continue end
		coroutine.wrap(tag)(b)
		coroutine.wrap(OnTouch)(b)
	end
end)

in the Module

local RenderModule = {}

local IsInScreen = {}

function RenderModule.getRecipes()
	return IsInScreen
end

return RenderModule

I wish UI had Streaming enabled so i woulnt have to code a render system

is anyone there???

Im on my phone right now so I cant give good code examples, but you could try using a 2d chunk system, so theres groups of notes per chunk, and it checks if the chunk should be loaded then loads all the notes within the chunk. Each chunk should be stored in a table with their x and y position, and all the notes they contain.

If you want to get what chunks that should be loaded, you’ll need the dimensions of each chunks, size of the frame, and how far the frame has “scrolled” on the x and y axis. Then you should be able to directly get what chunks should be loaded without having to even do any distance checks, because you can just index the chunk table where theyre stored.

I could give some code examples when im on later, ive done this a couple times in 3d but ill give a shot at 2d

each note is assigned to a separate frame based on what key it was in the midi file. using Y position will make the notes break. each note position Y pos = 0

plus they lag the game when i scroll through the scrolling frame

It works now. but i also realised it was the remote events constanly being fired for each note. thats why i have so much ping. but how do i optimize this as i want other players to hear the sounds.

Sorry for not providing a code example, I’ve been really busy lately and couldn’t get to it…

Nice! And about the remote events, you could use a resource called BridgeNet2 which greatly helps with performance related to networking.

Although, I can’t really help much more if you don’t provide more of your code. I also don’t know why you’d want everyone else to hear the sounds, as I have no idea what this is for. If you could give some more details that’d be great. If you still need help with the chunking system let me know, but it sounds like you got it figured out.