I'm trying to make it so when I click a part, all of the parts inside a model change Transparency from 1 to 0, and also change CanCollide from false to true. Please help.
I tried this, but it didn't work:
local children = game.Workspace.island1:GetChildren() local button = script.Parent function solid() children.Transparency = 0 children.CanCollide = true end button.ClickDetector.MouseClick:connect(solid)
The result of GetChildren
is a table; A list containing Roblox objects, such as parts.
You cannot directly change a property from the table.
Instead, you must iterate -- or "browse" -- through the table using a "generic for" loop, like so:
--[[ Tables contain key-value pairs. Each step of the loop, 'pairs' returns two values: A table key and the value associated with it. '_' and 'object' are variables. The former is assigned the key, a "position" in the table, and the latter is assigned the value associated to that key; In our case, a child of "Island1". ]] for _, object in pairs(game.Workspace.Island1:GetChildren()) do object.Transparency = 0 object.CanCollide = true end -- As a convention, we generally name the key '_' if we do not use its value.
I hope that answers your question; If it did, please make sure to mark my answer as accepted and optionally upvote. It helps both of us. If you still need anything, let me know.
for i,v in pairs(game:GetService("Workspace"):FindFirstChild("Island1"):GetChildren()) do v.Transparency = 0; v.CanCollide = true; end
just use a generic for loop to iterate through each element in the model at a a time. The i and v are variables which bind to each object's index, and each objects value.