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

when making a GetChildren script how to get 1 and change the transparency?

model = game.Workspace.Model:GetChildren()

for i, v in pairs(model) do

v.Transparency = 0.5

i = model [1]

i.Transparency = 0.8

end

It kinda works, but it isn't the first one as stated in the brackets.

1 answer

This changes all the parts transparency inside the model to 0.8 :

local Model = workspace.Model

for i, Part in ipairs(Model:GetChildren()) do
	Part.Transparency = 0.8
end

This changes the first part's transparency in the model to 0.5 :

local Model = workspace.Model:GetChildren()
local Part = Model[1]
Part.Transparency = 0.5

This changes the first part's transparency in the model to 0.5 and 0.8 to everything else :

local Model = workspace.Model:GetChildren()

for i, Part in ipairs(Model) do
	if Part == Model[1] then
		Part.Transparency = 0.5
	else
		Part.Transparency = 0.8
	end
end

This changes all the parts transparency inside the model to 0.8 then changes the first part's transparency to 0.5 :

local Model = workspace.Model:GetChildren()

for i, Part in ipairs(Model) do
	Part.Transparency = 0.8
end

local Part = Model[1]
Part.Transparency = 0.5

You can change this :

local Part = Model[1]
Part.Transparency = 0.5

To this :

Model[1].Transparency = 0.5

2 comments

0

Use ipairs(). GetChildren() returns an array and ipairs() is made specifically for arrays.

0

oh... i didn't know that, thanks i'll edit it

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