Script not detecting Name above number 100

There’s a folder that contains Mini001, Mini002 until Mini232

I used this script provided. But it did not detect anything above 099, so Mini100 just doesnt work properly. any fixes?

local MinIndex = 1
local MaxIndex = 232
local CurrentIn = 0
local Path = script.Parent

for current = MinIndex, MaxIndex do
	CurrentIn = CurrentIn + 1
	local Names = "Mini000"
	if CurrentIn < 10 then
		Names = "Mini00"..CurrentIn
	else
		Names = "Mini0"..CurrentIn
	end

	local lights = Path[Names].lights
	local water = Path[Names].Main.Nozzle.Water
	local refill = Path[Names].Main.Nozzle.Refill

	water:GetPropertyChangedSignal("Enabled"):Connect(function()
		for _, bulb in ipairs(lights:GetChildren()) do
			bulb.light.Brightness = 1
			bulb.light.Enabled = true
			bulb.Material = "Neon"
		end
	end)
	refill:GetPropertyChangedSignal("Enabled"):Connect(function()
		for _, bulb in ipairs(lights:GetChildren()) do
			bulb.light.Enabled = false
			bulb.Material = "Glass"
		end
	end)
end

That’s because the if statement does not consider 3 digits.
Add an if CurrentIn < 100 then statement to fix this.

	
	elseif CurrentIn < 10 then
		Names = "Mini00"..CurrentIn
	elseif CurrentIn < 100 then
		Names = "Mini0"..CurrentIn
	else
		Names = "Mini"..CurrentIn
	end

There is a simpler way to format this, for your knowledge.

Also, why did you define a name for the for loop variable, and then proceed to use a new variable? Just replace CurrentIn with current, and remove the CurrentIn = CurrentIn + 1 line.

2 Likes

right cause if the CurrentIn, for example is equal to 100 then if he used this script:

if CurrentIn < 10 then
		Names = "Mini00"..CurrentIn
	else
		Names = "Mini0"..CurrentIn
	end

then it will resulted in “Mini0100” which is not desirable

The scripter was provided to me on this forum
Need help on making a script that detects particle enabled then turn on lights - Help and Feedback / Scripting Support - Developer Forum | Roblox

I just tested it and it works, thank you so much. This’ll be very helpful I’m still new to scripting

1 Like

I think that it’s best to remember that you should always try and comment each line or block of code just so you know what it does when you come to changing it.
And welcome, have fun scripting!

1 Like

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