I have 2 models that I want to make transparent after somebody touches a part (Gear and Fakegear) Right now this script works fine but writing pointPart.Gear.Gear1.Transparency = 0.5 a million times doesn't look very good, but when I try to change the transparency using just the model, it doesn't work. How do I make all these parts transparent without writing it out 500 times? (Sorry if it's a nooby question)
local pointPart = script.Parent -- Colors local blue = Color3.fromRGB(0, 0, 255) local green = Color3.fromRGB(0,255,0) -- Services needed local Players = game:GetService("Players") local canGet = true local function onTouch(otherPart) local humanoid = otherPart.Parent:FindFirstChild('Humanoid') local player = game.Players:FindFirstChild(otherPart.Parent.Name) local currentColor = pointPart.Color if humanoid and player and canGet and currentColor == blue then canGet = false player.leaderstats.Gears.Value = player.leaderstats.Gears.Value + 1 print("Giving player gear") pointPart.Color = green pointPart.Parent.Gear.Gear1.Transparency = 0.5 pointPart.Parent.Gear.Gear2.Transparency = 0.5 pointPart.Parent.Gear.Gear3.Transparency = 0.5 pointPart.Parent.Gear.Gear4.Transparency = 0.5 pointPart.Parent.Gear.Gear5.Transparency = 0.5 pointPart.Parent.Gear.Gear6.Transparency = 0.5 pointPart.Parent.Gear.Gear7.Transparency = 0.5 pointPart.Parent.Gear.Gear8.Transparency = 0.5 wait(5) game.Workspace.Fakegear.Gear1.Transparency = 0.5 game.Workspace.Fakegear.Gear2.Transparency = 0.5 game.Workspace.Fakegear.Gear3.Transparency = 0.5 game.Workspace.Fakegear.Gear4.Transparency = 0.5 game.Workspace.Fakegear.Gear5.Transparency = 0.5 game.Workspace.Fakegear.Gear6.Transparency = 0.5 game.Workspace.Fakegear.Gear7.Transparency = 0.5 game.Workspace.Fakegear.Gear8.Transparency = 0.5 canGet = true elseif humanoid and player and canGet and currentColor == green then print("Player already recieved gear") end end pointPart.Touched:Connect(onTouch)
Use a foreach (or enhanced for) loop! It'll look something like this:
for i, block in model:GetChildren() do if block:IsA("Part") then block.Transparency = 0.5 end end
Try using a model script in the model see if that will work Hope this helps!!