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

Does tables get syntax errors?

Hi! I had a group that has parts in it. The group/Model is called RemovePortals. I try and get the parts in one variable so I scripted this: (There is also a same group with the same problem called CDE)

local RemovePortals = game.Workspace.Tycoon.RemovePortal:GetChildren()
local CDE = game.Workspace.Tycoon.CDE:GetChildren()

So I want to get the children of those groups and make the children transparency = 1 and CanCollide = true. So I used GetChildren() to get the parts in one variable and it did not work. I heard it gets all the children and returns them in a table. So do I really need to get each child of both of the groups or can I use another shortcut/Variable?

1 answer

✓ Accepted answer

You can use a for loop to solve your problem.

-- variables
local RemovePortals = game.Workspace.Tycoon.RemovePortal:GetChildren()
local CDE = game.Workspace.Tycoon.CDE:GetChildren()

-- loops
for index, part in pairs(RemovePortals) do
	if part:IsA("Part") then
		part.Transparency = 1
		part.CanCollide = false
	end
end

for index, part in pairs(CDE) do
	if part:IsA("Part") then
		part.Transparency = 1
		part.CanCollide = false
	end
end

These for loops will loop through the whole table, RemovePortals and CDE. part indicates the currently chosen part in the table. If it actually is a Part we will set the Transparency property to 1 and the CanCollide property to false.

1 comment

0

Thank you!! It worked! (I actually meant traansparency = 0 and cancollide = true but my bad) I appreciate that!

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