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

How do I make a model transparent on touch without writing out all it's contents?

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)

2 answers

✓ Accepted answer

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

1 comment

0

This worked after a bit of tweaking to help it fit my code, thanks!

Try using a model script in the model see if that will work Hope this helps!!

1 comment

0

I don't really understand what you're trying to say. What is a model script? and what am I supposed to put inside of it?

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