So, in my model, there are 24 parts that are named "S1, S2, S3, S4, S5, S6, S7, S8, etc..."
I want to know if there is a way to find the certain part based on the fill/num value. For example, "1" is "S1", and "2" is "S2", and "3" is "S3", and so on and so forth.
I can always do a long version of declaring the variables and have if statements to check but there should be a short easier and efficient way of processing this. Perhaps I will need to make a library of some sort, I'm not sure.
local set = script.Parent.Fill.Value
local Level1 = script.Parent.Level1
num = 0
i = 0
if num ~= set then
repeat
num = num + 1
i = i + 1
print ("Count".. i)
wait()
until num == set
if num == set then --Here is where I need to find an efficient way of processing things.
Level1.S1.Transparency = 0
Level1.S1.CanCollide = true
end
end
script.Disabled = true
What I want it to do? To search and process by the associated number of the part's name and initiating the following effects afterwards. Which would be the Transparency and Collision change of the part.
Update: Here is the longer and tedious version of processing the index. Is not really necessary for an incrementing count , so long as the "set":
local num = script.Parent.Fill.Value
-which is now named as "num" is the value of the associated part. Basically, is directly associated to the value given for num to check.
local num = script.Parent.Fill.Value --Make sure to change it back to "set" if going to use the counting part
--Library--
local S1 = script.Parent.Level1.S1
local S2 = script.Parent.Level1.S2
local S3 = script.Parent.Level1.S3
local S4 = script.Parent.Level1.S4
local S5 = script.Parent.Level1.S5
local S6 = script.Parent.Level1.S6
local S7 = script.Parent.Level1.S7
local S8 = script.Parent.Level1.S8
local S9 = script.Parent.Level1.S9
local S10 = script.Parent.Level1.S10
local S11 = script.Parent.Level1.S11
local S12 = script.Parent.Level1.S12
--num = 0
--i = 0
--if num ~= set then
--repeat
-- num = num + 1
--i = i + 1
--print ("Count".. i)
-- wait()
--until num == set
--Initiate Search--
if num == 1 then
print ("S1 Added!")
S1.Transparency = 0
S1.CanCollide = true
else
if num == 2 then
print ("S2 Added!")
S2.Transparency = 0
S2.CanCollide = true
else
if num == 3 then
print ("S3 Added!")
S3.Transparency = 0
S3.CanCollide = true
else
if num == 4 then
print ("S4 Added!")
S4.Transparency = 0
S4.CanCollide = true
else
if num == 5 then
print ("S5 Added!")
S5.Transparency = 0
S5.CanCollide = true
else
if num == 6 then
print ("S6 Added!")
S6.Transparency = 0
S6.CanCollide = true
else
if num == 7 then
print ("S7 Added!")
S7.Transparency = 0
S7.CanCollide = true
else
if num == 8 then
print ("S8 Added!")
S8.Transparency = 0
S8.CanCollide = true
else
if num == 9 then
print ("S9 Added!")
S9.Transparency = 0
S9.CanCollide = true
else
if num == 10 then
print ("S10 Added!")
S10.Transparency = 0
S10.CanCollide = true
else
if num == 11 then
print ("S11 Added!")
S11.Transparency = 0
S11.CanCollide = true
else
if num == 12 then
print ("S12 Added!")
S12.Transparency = 0
S12.CanCollide = true
end
end
end
end
end
end
end
end
end
end
end
end
--end
script.Disabled = true
Still looking for a better way of shortening this code with a more efficient processing of the index. Will help save me *time *and pain. lol
Update 2: For anyone who wants to know the finished outcome of this question, here is the following code:
local set = script.Parent.Fill.Value
local MyModel = game.Workspace.A.Level1
local Data = {
[MyModel.S1] = 1,
[MyModel.S2] = 2,
[MyModel.S3] = 3,
[MyModel.S4] = 4,
[MyModel.S5] = 5,
[MyModel.S6] = 6,
[MyModel.S7] = 7,
[MyModel.S8] = 8,
[MyModel.S9] = 9,
[MyModel.S10] = 10,
[MyModel.S11] = 11,
[MyModel.S12] = 12,
}
for i,v in pairs(Data) do --"Data" is pretty much "i,v", in which "i" is MyModel.S1 and "v" is "1".
if v == set then --So, "v" is the number value that is used to compare the value for "set".
print(i,v) --Checks the order in the output view window.
i.Transparency = 0
i.CanCollide = true
end
end
script.Disabled = true
Thanks for the help and information! Much appreciated!~
