You would use a for loop to loop through all the children. For example:
for _, Part in ipairs(BusModel:GetChildren()) do -- We're looping through all the children of "BusModel". Note this includes all objects (folders, other models, etc)
if Part:IsA("BasePart") then -- make sure its a part
Part.Transparency = 1;
end;
end;
You would put it inside your onTouched() function:
function onTouched ()
for _, Part in ipairs(BusModel:GetChildren()) do -- We're looping through all the children of "BusModel". Note this includes all objects (folders, other models, etc)
if Part:IsA("BasePart") then -- make sure its a part
Part.Transparency = 1;
end;
end;
end
There might be typos so just double check in the script editor.
local Players = game:GetService("Players")
local BusModel = workspace.Bus
local Trigger = script.Parent
local function OnTouched(Hit)
local Player = Players:GetPlayerFromCharacter(Hit.Parent)
if Player then
for _, BusPart in ipairs(BusModel:GetChildren()) do
if BusPart:IsA("BasePart") then
BusPart.Transparency = 1
end
end
end
end
Trigger.Touched:Connect(OnTouched)
You should declare variables/define functions locally (by preceding them with the local keyword), by doing this they are integrated into the local environment which allows for them to accessed/referenced much quicker when necessary (as doing this circumvents the need to index the global environment table in order to fetch their values). You should also be checking that the “Touched” event of the trigger part fired because it was touched by a player’s character otherwise any touching part will result in the connected function executing fully.