My code is not running and I don't know how to fix it

Hi,

Basically, I’ve tried to fix this code in many different ways, but it is still not working:

--// Instance count \\--
	
	local instances = 0
	local parts = 0
	local unions = 0
	local sounds = 0
	local scripts = 0
	local miscs = 0
	local lightings = 0
	local constraints = 0
	local values = 0
	local effects = 0
	local uis = 0
	
	for i, v in pairs(game:GetDescendants()) do
		
		if v:IsA("BasePart") then
			
			parts += 1
			
		elseif v:IsA("UnionOperation") then
			
			unions += 1
			
		elseif classesmod.ui[v.ClassName] then
			
			uis += 1
			
		elseif classesmod.sound[v.ClassName] then

			sounds += 1
			
		elseif classesmod.scripts[v.ClassName] then

			scripts += 1
			
		elseif classesmod.lighting[v.ClassName] then

			lightings += 1
			
		elseif classesmod.constraints[v.ClassName] then

			constraints += 1
			
		elseif classesmod.effects[v.ClassName] then

			effects += 1
			
		elseif classesmod.values[v.ClassName] then

			values += 1
			
		else
			
			miscs += 1
			
		end
		
	end

        -- debugging

        print(tostring(uis))

Here, “classesmod” is a module script with tables for each class, for example, “UI” is a table with everything related to UI inside. What’s wrong is that when I print “uis”, it prints “0” even tho I have a lot more than 0 UI elements in my game.

If anyone could fix this, it would be much appreciated!

I would make sure your letting the game load before letting your script run (As my first thought). Can we see this module script?

Surely! Here:

local classes = {}

classes.ui = {

	"ScreenGui",
	"BillboardGui",
	"SurfaceGui",
	"CoreGui",
	"DockWidgetPluginGui",
	"CanvasGroup",
	"Frame",
	"ScrollingFrame",
	"ViewportFrame",
	"VideoFrame",
	"TextLabel",
	"TextButton",
	"TextBox",
	"ImageLabel",
	"ImageButton",
	"UIAspectRatioConstraint",
	"UICorner",
	"UIGradient",
	"UIGridLayout",
	"UIListLayout",
	"UIPadding",
	"UIPageLayout",
	"UIScale",
	"UISizeConstraint",
	"UIStroke",
	"UITableLayout",
	"UITextSizeConstraint"

}

classes.sound = {

	"Sound",
	"SoundGroup",
	"ChorusSoundEffect",
	"CompresserSoundEffect",
	"DistortionSoundEffect",
	"EchoSoundEffect",
	"EqualizerSoundEffect",
	"FlangeSoundEffect",
	"PitchShiftSoundEffect",
	"ReverbSoundEffect",
	"TremoloSoundEffect"

}

classes.scripts = {

	"Script",
	"LocalScript",
	"ModuleScript"

}

classes.lighting = {

	"PointLight",
	"SpotLight",
	"SurfaceLight",
	"BloomEffect",
	"BlurEffect",
	"ColorCorrectionEffect",
	"DepthOfFieldEffect",
	"SunRaysEffect",
	"Atmosphere",
	"Clouds",
	"Sky"

}

classes.constraints = {

	"AlignOrientation",
	"AlignPosition",
	"AngularVelocity",
	"Attachement",
	"BallSocketConstraint",
	"CylindricalConstraint",
	"HingeConstraint",
	"LinearVelocity",
	"LineForce",
	"NoCollisionConstraint",
	"PlaneConstraint",
	"PrismaticConstraint",
	"RigidContraint",
	"RodConstraint",
	"RopeConstraint",
	"SpringConstraint",
	"Torque",
	"TorsionSpringConstraint",
	"UniversalConstraint",
	"VectorForce",
	"WeldConstraint"

}

classes.effects = {

	"Beam",
	"Explosion",
	"Fire",
	"Highlight",
	"ParticleEmitter",
	"Smoke",
	"Sparkles",
	"Trail",
	"WrapLayer",
	"WrapTarget"

}

classes.values = {

	"BoolValue",
	"BrickColorValue",
	"CFrameValue",
	"Color3Value",
	"IntValue",
	"NumberValue",
	"ObjectValue",
	"RayValue",
	"StringValue",
	"Vector3Value"

}

return classes
1 Like

Instead of this for your elseif statements try something like (for all of them that use the module script):

elseif table.find(classesmod.ui, v.ClassName) then

Wow! This is my first topic ever and I did not expect an answer that fast. Thanks a lot (:

1 Like

No worries! I’m glad it works!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.