Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make this list work?

Asked by 9 years ago

I built blockers for a security checkpoint, but I dont know how to make the script more efficient. I want to do something like this. \/ This is what I came up with, but it does not work. Could I have help?

a = script.Parent.Parent.Parent.Blocker.a
b = script.Parent.Parent.Parent.Blocker.b
c = script.Parent.Parent.Parent.Blocker.c
d = script.Parent.Parent.Parent.Blocker.d
e = script.Parent.Parent.Parent.Blocker.e
f = script.Parent.Parent.Parent.Blocker.f
g = script.Parent.Parent.Parent.Blocker.g
h = script.Parent.Parent.Parent.Blocker.h
i = script.Parent.Parent.Parent.Blocker.i
j = script.Parent.Parent.Parent.Blocker.j
blockers = {a,b,c,d,e,f,g,h,i,j}

--when this button is clicked, the blocking bricks change to 0 transparency and non-collide
function onClicked()
    blockers.Transparency = 0
    blockers.CanCollide = true
end



script.Parent.ClickDetector.MouseClick:connect(onClicked)

1 answer

Log in to vote
2
Answered by
Bman8765 270 Moderation Voter
9 years ago

You are trying to change a table value, the table value does not have transparency. Think of it like this, a table isn't the variable it just holds the variables kinda like your dresser (if you have one) holds your socks but you can't see the color of the socks until you open the dresser drawer and tell it which sock you want . You can use a for loop to do this by looping the amount of items in the table and giving the current number it is on a variable... kinda confusing but I'll explain. Example:

exampletable = {1,2,"a","d",c = 12, q = 20}

for i,v in pairs(exampletable) do
    print(v)
end

v is the current "number" it goes to like in an example for statement it is the second value but instead of it being an actual number value it's a variable (this works with getting the children of something to). It will then do this in the pairs of example table (inpairs tutorial: http://wiki.roblox.com/index.php?title=Function_dump/Basic_functions#pairs ) I guess to sum that all up it basically goes through the number of items in a table. So in your case this should be a simple solution:

a = script.Parent.Parent.Parent.Blocker.a
b = script.Parent.Parent.Parent.Blocker.b
c = script.Parent.Parent.Parent.Blocker.c
d = script.Parent.Parent.Parent.Blocker.d
e = script.Parent.Parent.Parent.Blocker.e
f = script.Parent.Parent.Parent.Blocker.f
g = script.Parent.Parent.Parent.Blocker.g
h = script.Parent.Parent.Parent.Blocker.h
i = script.Parent.Parent.Parent.Blocker.i
j = script.Parent.Parent.Parent.Blocker.j
blockers = {a,b,c,d,e,f,g,h,i,j}

--when this button is clicked, the blocking bricks change to 0 transparency and non-collide
function onClicked()
    for i,v in pairs(blockers) do
            v.Transparency = 0
            v.CanCollide = true
    end
end



script.Parent.ClickDetector.MouseClick:connect(onClicked)

If this helped make sure to click Accept Answer If you have any questions just ask!

0
Hey, it works, but the bricks go away slowly one at a time. Is it possible to fix this? My_Comment 95 — 9y
0
Anchor them? Bman8765 270 — 9y
1
You could simply move, or remove, the wait() function so it is not inside of the for loop. Normally, you would have to be cautious when doing this, as it could cause your studio to crash if it creates an infinite loop, but in this case, as the values are all pre-defined, it should be fine.  Trewier 146 — 9y
0
Thanks for pointing that out iLiminate, I changed the answer because it truly is not necessary Bman8765 270 — 9y
View all comments (4 more)
0
Fixed Bman8765 270 — 9y
0
@ilim I saw that and changed that. My_Comment 95 — 9y
2
Thanks for both of your guy's help... You are awesome! My_Comment 95 — 9y
0
Also, the first 11 lines could probably be rescripted to something like this: blockers = {} for i,e in pairs(script.Parent.Parent.Parent.Blocker.getChildren()) do table.insert(blockers,e) end table.sort() This is of course assuming that the only children of blocker are, (a,b,c,etc.) otherwise you could just stick with what you have now. Trewier 146 — 9y
Ad

Answer this question