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

Why will this attempt at making multiple variables into one variable not work?

Asked by 10 years ago
--each letter after "Blocker" is a Part.
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}


function onClicked()
    blockers.Transparency = 0
    blockers.CanCollide = true

    end



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

2 answers

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

In your code, blockers is a list.

A list does not have a Transparency property or CanCollide property, so modifying that would accomplish nothing.

Instead, you have to consider each element in the list:

for index, object in pairs( blockers ) do
    object.Transparency  = 0
    object.CanCollide = true
end

As DevFrank pointed out, the way you're defining blockers is unnecessarily long. You could instead just consider all of the Children of script.Parent.Parent.Parent.Blocker that are Parts.

So we change blockers to

blockers = script.Parent.Parent.Parent.Blocker:GetChildren()

but make sure each object IsA Part:

for index, object in pairs( blockers ) do
    if object:IsA("BasePart") then
        object.Transparency  = 0
        object.CanCollide = true
    end
end

If this "doesnt work", you should consult the output and provide that. Only so much help can be given when you give only a little information.

2
You made a typo in your code. Was this on purpose? Tkdriverx 514 — 10y
0
Typos should be fixed BlueTaslem 18071 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your answer.

So when using ":GetChildren()" it creates a table of the children that you have decided to get from the object. Then when using for "for _,v in pairs(example:GetChildren) do" is a more sufficient way then doing, "for i = 1,#example:GetChildren() do". Then we must check if the object is a part in this case, which we use, :IsA("CLASSNAME") . Then after that I believe you understand already.

I will use a better way to do this in your situation.

script.Parent.ClickDetector.MouseClick:connect(function()
for _,v in pairs(script.Parent.Parent.Parent.Blocker:GetChildren()) do
if v:IsA("BasePart") then
v.Transparency = 0
v.CanCollide = true
end
end
end)

I also decided to use BasePart because I never knew it existed.

If you don't understand what I was trying to explain above, then let me post some links to the wiki. I did edit this because I felt that I wasn't telling you enough.

http://wiki.roblox.com/index.php?title=API:Class/Instance/GetChildren

http://wiki.roblox.com/index.php?title=Function_dump/Basic_functions#pairs

http://wiki.roblox.com/index.php?title=API:Class/BasePart

Don't forget to mark this as solved and as the correct answer!

0
Doesnt work qq My_Comment 95 — 10y
0
Are a,b,c,d,e,f,g,h,i,j parts? YasuYoshida 171 — 10y
0
Yeah, like it said at the top. My_Comment 95 — 10y
0
Try it now, if it doesn't work then it must be something else. You should try posting your error next time. YasuYoshida 171 — 10y

Answer this question