This is just a script in a gui and Idk how to make it a better way.
01 | script.Parent.Parent.Car 1. Visible = false |
02 | script.Parent.Parent.Car 2. Visible = false |
03 | script.Parent.Parent.Car 3. Visible = false |
04 | script.Parent.Parent.Car 4. Visible = false |
05 | script.Parent.Parent.Car 5. Visible = false |
06 | script.Parent.Parent.Car 6. Visible = false |
07 | script.Parent.Parent.Car 7. Visible = false |
08 | script.Parent.Parent.Car 8. Visible = false |
09 | script.Parent.Parent.Car 9. Visible = false |
10 | script.Parent.Parent.Car 10. Visible = false |
The wonderful world of for loops, where anything is possible!
1 | for i = 1 , 10 do |
2 | script.Parent.Parent [ "Car" .. i ] .Visible = false |
3 | end |
This type of for loop will start at 1 and increase to 10, storing the value in i. There are also generic for loops (for a, b, c, ... in func, val1, val2, val3, ... do
), but they need a little more explaining (and are not what you need at the moment).
I'm not realy sure if there are ONLY Items named Car with a number, so here are two scripts depending on that.
If there are items named other than Car<number>
1 | validnames = { "Car1" , "Car2" , "Car3" , "Car4" , "Car5" , "Car6" , "Car7" , "Car8" , "Car9" , "Car10" } |
2 |
3 | for i,v in ipairs (script.Parent.Parent:GetChildren()) do |
4 | if validnames [ v.Name ] then |
5 | v.Visible = false |
6 | end |
7 | end |
If there are ONLY items named Car<number>
1 | for i,v in ipairs (script.Parent.Parent:GetChildren()) do |
2 | v.Visible = false |
3 | end |