When I stand on these platforms in the game, I get terrible lags.
But when I get in an empty game, everything is fine.
Script
local list = script.Parent:GetChildren()
table.remove(list,table.find(list,script.Parent.Script))
for _, spawn in pairs(list) do
task.spawn(function()
local Neon = spawn.Neon
local Center = spawn.RotatingCircle.Center
local Col = spawn.Collision
local ovr = OverlapParams.new()
local CF = Col.CFrame
local Ve = Col.Size
local i = -1
while task.wait(0.01) do
i +=1
local list = workspace:GetPartBoundsInBox(CF,Ve,ovr)
while #list == 1 do
Neon.Color = Color3.fromHSV((i-1)/360, 1, 0.4)
Col.Touched:Wait()
list = workspace:GetPartBoundsInBox(CF,Ve,ovr)
end
if i == 360 then i = 0 end
Neon.Color = Color3.fromHSV(i/360, 1, 0.666667)
Center.CFrame = CFrame.new(Center.Position)*CFrame.Angles(0,math.rad(i),0)
end
end)
end
I tested and verified that the lag begins precisely because of the color change.
Immediately to clarify, in my game every 20 seconds deletes more than 1000 parts, and creates new ones (loading/deleting maps)
I just can’t figure out where the connection is between a simple color change, and loading a map that consists of a bunch of parts.
And okay would be a little lag, but on the video it was not much, but when I tested with a friend in the game, fps dropped 2-3 times.
Here’s suppose I started loading the map, okay will be micro lag, but if I stand on the platform, then lag will be long, and a lot. where is the logic?
I believe you have certain functions that are cost-intensive when it comes to calling them. Because Touched is fired multiple times, the two nested while loops will unleash hell upon your resources and rob every piece of performance from you, creating lag.
Perhaps you can find a different implementation that helps avoiding calling something too many times?
I am guessing that workspace:GetPartBoundsInBox(CF,Ve,ovr) adds more complexity to the loop and could result in degraded performance(throttling). There are a lot of calls on it too whenever the loop goes without any yielding, assuming that #list ~= 1 and constant Touched event.
However, I was also wondering. Does non-neon parts impact the performance as well?