So I have a touch script for UI that detects if the playerhead touches the notes
but as the band gets bigger, the lag intensifies
this is the code that detects all the notes
local RunService = game:GetService("RunService")
local Collectionservice = game:GetService("CollectionService")
local GuiCollisionService = require(game:GetService("ReplicatedStorage").GuiCollisionService)
function OnTouch(b)
local a = b.Parent.Parent.Parent.Parent.DragableFrame
local debounce = false
GuiCollisionService.isColliding(a, b)
if GuiCollisionService.isColliding(a,b) == true then
b.UIStroke.Enabled = true
repeat task.wait()
until GuiCollisionService.isColliding(a,b) == false
b.UIStroke.Enabled = false
end
end
RunService.RenderStepped:Connect(function()
for i, b in pairs(Collectionservice:GetTagged("regions")) do
if b.Parent.Parent.Parent.Parent.Parent.Parent.Playback.Aplay.paused.Value == false then
coroutine.wrap(OnTouch)(b)
end
end
end)
Is there any way i can compress and optimize this?