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

Why won't this script get all the bricks it needs to?

This script is supposed to grab all of the bricks inside of the appropriate folder, but it keeps returning an error telling me it's expecting a table instead of an object. I am AWFUL at working with this "in pairs" stuff. Can someone help?

        func = function( p ) -- functions go HERE
            print(p.Name .. " toggled privacy mode")
			if privacymodeon == false then
			game.Workspace.FaraVoice.Value = "Very well, sir."
			for i, v in pairs(game.Workspace.FaradayHouse.Body.Windows) do
				if v:IsA("BasePart") then
				if v.Name == "Glass" then
				v.Transparency = 0.1
				end
				end
				end
			end
			if privacymodeon == true then
			game.Workspace.FaraVoice.Value = "Privacy mode is now off, sir."
			for i, v in pairs(game.Workspace.FaradayHouse.Body.Windows) do
				if v:IsA("BasePart") then
				if v.Name == "Glass" then
				v.Transparency = 0.6
				end
				end
			end
			
			end
			
        end

2 comments

0

Can we have what line the error is on?

0

Line 5, so assumedly like 14 would have it, too.

1 answer

✓ Accepted answer

in pairs () requires a table, not an object. If you want to cycle through it's children:

for _,v in pairs (game.Workspace.FaradayHouse.Body.Windows:GetChildren()) do -- GetChildren() returns an array of objects
	-- code
end

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