Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

"Expected Table, got object" Error?

So I'm new to scripting, and just watched a vid on the for i,v in pairs thing last night. I tried using it, but it won't do anything. The output says something about Expected Table, got Object? Here is my code:

local Part = game.Workspace.Part
for i,v in pairs(Part) do
v.Transparency = 1
end

But it isn't working. Please answer if you have any idea whats wrong, as i'm new to scripting and any help is acceptable

1 answer

The code expects there to be a table inside of the parentheses after pairs. Instead of providing a table you are giving it a part of the workspace. If you are trying to make all the parts in the workspace turn invisible then you might want to do this:

for i,v in pairs(game.Workspace:GetChildren()) do -- the getchildren method  returns a table of all the children of an object
end

otherwise if you are trying to turn all the parts in a model invisible then you will need to call the :GetChildren() method on that model to receive a table with its children. I hope this helps and have a great day scripting!

This discussion is preserved as it was. New answers, comments, and votes are closed.