Without assigning a transparency value to each part.
✓ ANSWER ACCEPTED
Can you make a whole model transparent?
2 answers
✓ Accepted answer
As M39a9am3R wrote, you can achieve this by using a loop. However, if your model has submodels, you'll encounter a problem with just a single loop. To solve that issue, you can create a recursive function - a function that can call itself inside itself.
-- param:
-- Instance model,
-- String property,
-- Undefined value
function setProperty(model, property, value) -- *1,
for _, obj in pairs(model:GetChildren()) do
pcall(function() -- *2
if obj[property] then -- *3
obj[property] = value -- *4
end
end)
setProperty(obj, property, value) -- *5
end
end
-- Let's run the function
setProperty(game.Workspace.myModel, "Transparency", 0.7)
--[[
--Explaining further--
*1: model::Instance is root model (target), property::String is the name of the property you wish to change, value::Undefined is the value you wish to set the property to
*2: Adding a pcall to make sure the script continues even if it errors. You can additionally add an error-message - check pcall documentation/API
*3: making sure we can actually set the property by checking it's validity.
*4: setting obj's [property] to value. Treating it like a table.
myModel.Name can be written as myModel["Name"], and this works for other properties as well. We take advantage of this!
5*: We'll run obj through our function, in case it has any children
]]
You would need a loop to go through all the parts of the model,
for _,v in pairs(game.Workspace.MODELNAMEHERE:GetChildren()) do --So GetChildren makes a table, v is the value of the item.
if v:IsA("BasePart") then --If v is a brick or wedge part or something like that, then the code to come will run.
v.Transparency = .5 --The brick is changed to .5 Transparency.
end
end
This discussion is preserved as it was. New answers, comments, and votes are closed.
