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

How to locate a part using a variable?

Probably some silly mistake. The error code is Children is not a valid member of model

Children = script.Parent.Model:GetChildren()
script.Parent.Model.Children.Transparency = Variable

Thats just my problem but if the entire code is necessary here it is

Children = script.Parent.Model:GetChildren()
Variable = 0
Des = 0.01
OrDes = Des

function ftrancparency ()
	Variable = Variable + Des
	script.Parent.Model.Children.Transparency = Variable
end

while true do
	wait()
	
	ftrancparency()
	
	if Variable >= 1 then
		script.Parent.Model.Children.CanCollide = false
		wait (5)
		Des = -OrDes
	end
	
	if Variable <= 0 then
		script.Parent.Model.Children.CanCollide = true
		wait (10)
		Des = OrDes
	end
	
end

1 answer

✓ Accepted answer

Children returns a table/list/array of all descendants of "Model". You can't set a table's transparency, so you have to cycle through the list.

for i, v in pairs(script.Parent.Model:GetChildren()) do
	v.Transparency = Variable;
end

2 comments

0

I dont really understand, but it worked. Thanks!

0

If you want to try and think of it in a simplified way, GetChildren() gives you a list of everything inside the object (in this case, the model). You don't want to set the list's transparency, right? You want all of the children's transparency. So, you use a modified for loop to cycle through all of the object's children and change it's transparency.

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