Is it normal to have this many instances?
Im trying my best to reduce lag in my game the game right now has about 65k parts but when i was looking at the parts i noticed the number of instances is this normal? It doesnt feel normal to me…
And if its not how can i get rid of some? Without restarting everything.
That’s def quite a few parts. You can try to anchor as many parts as possible, that will help greatly to reduce lag since anchored parts aren’t involved in the physics calculations. You can also look into Content Streaming | Roblox Creator Documentation
Any idea what the other instances are? If not, you can copy/paste this script into the Command Bar, and you should get something like this in your Output:
ClassName count snippet
local function countClasses(ancestors)
local countsDict = {}
for _, ancestor in ipairs(ancestors) do
for _, d in ipairs(ancestor:GetDescendants()) do
countsDict[d.ClassName] = (countsDict[d.ClassName] or 0) + 1
end
end
local countsArray = {}
for className, count in pairs(countsDict) do
table.insert(countsArray, {ClassName = className, Count = count})
end
table.sort(countsArray, function(a, b)
return a.Count > b.Count
end)
local longestClassName = ""
local longestCountDigits = 0
for className, count in pairs(countsDict) do
if className:len() > longestClassName:len() then
longestClassName = className
end
if math.log10(count) > longestCountDigits then
longestCountDigits = math.ceil(math.log10(count))
end
end
local formatStr = ("%%%ds %%%dd"):format(longestClassName:len(), longestCountDigits)
local countsSum = 0
for _, v in ipairs(countsArray) do
countsSum += v.Count
end
print(formatStr:format("Total", countsSum) .. " %")
formatStr ..= (" %5.1f%%")
for _, v in ipairs(countsArray) do
print(formatStr:format(v.ClassName, v.Count, 100 * (v.Count / countsSum)))
end
end
countClasses({game.Workspace, game.ReplicatedStorage, game.ReplicatedFirst, game.ServerStorage, game.ServerScriptService, game.StarterPlayer, game.StarterGui, game.Teams, game.Lighting, game.Players})
If you don’t have those windows open, you can do so in the VIEW tab:
Please make sure you’ve saved your place BEFORE running other people’s code in the command bar, and make sure you DON’T SAVE AFTER running it. If it makes any unwanted changes you will not be able to undo them, although this specific script doesn’t make any changes. Could crash your Studio, so again at the very least make sure you save before running the script.
Here’s the output from an untouched new baseplate place:
Total 14
Decal 1 7.1%
Sky 1 7.1%
Camera 1 7.1%
BloomEffect 1 7.1%
Atmosphere 1 7.1%
BoolValue 1 7.1%
Part 1 7.1%
SunRaysEffect 1 7.1%
SpawnLocation 1 7.1%
StarterPlayerScripts 1 7.1%
StarterCharacterScripts 1 7.1%
Terrain 1 7.1%
DepthOfFieldEffect 1 7.1%
Texture 1 7.1%
For some reason for my total i got doesnt match the instance count…
Total 163064
I don’t know how you’re counting instances to get the 1.6 million figure from the OP, but it’s most likely because some places aren’t included in the script I posted. Try changing the last line to
countClasses({game})
or just add the missing places to the list.
It’s because some instances exist in memory (are not attached to the DataModel) or don’t exist in developer-facing services (cannot be accessed by Script security context level). See InstanceCount.
I turned this snippet into a plugin if anyone would like to use it!
(first off, yes I know this is a very old post)
while messing around I found an interesting bit of information regarding instances(more specifically the ones that show up in the counter but not in workspace and such)
what I found, was the following:
When you’re in roblox studio:
Clicking inside the View Model adds 6 instances that are Semi-persistent
When you hover over an object it adds 5 Semi-persistent instances as well
it adds 5 if you start hovering over something, but just moving between hovering objects it just adds one
Using the selection box will add one instance per object selected, however when you deselect they actually get removed
It appears as though these aren’t completely persistent though, as it appears as they’re removed upon reloading the world, meaning they’re most likely just cached for some reason, but it could also be something that was overlooked when they were making it