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

Question for very simple script?

I'm trying to make a model named "Gator" become transparent after a few seconds. As simple as it may be for some of you, it's difficult for me due to my limited knowledge with scripting. Here's the script :

wait(10)
game.Workspace.Gator.Transparency = 1

Simple right? Can someone please help? The output says "Transparency is not a valid member of Model"

2 comments

1

It's important to know the properties of the objects you're working with http://wiki.roblox.com/index.php?title=Property

0

Some objects have very different rolls from one another, thus, having very different properties.

3 answers

Hey, AdmiralToro.

When we speak of models, they are not parts. You can`t set a models transparency, its not a property. To accomplish what you're trying to do, you'd have to make every part in that model transparent.(As Transparency is indeed a property of Part)

What you could do

Use a for loop that will iterate through all the parts in the Gator Table.

local gator = game.Workspace:WaitForChild("Gator") --Waiting for your model and creating a gator variable

for i, v in pairs(gator:GetChildren()) do
	
end

The GetChildren method creates a list(Table) of all the items inside that model. We then use the for loop to iterate through all the children in that model. The i stands for index and v for value, however you can replace i and v with whatever you want. This loop will run as many times as there are objects in the model.(If you have twenty parts, it will run twenty times)

In this case, the first time the loop runs, the i would be the number 1 and the v would be the 1st part in the table.

for i, v in pairs(gator:GetChildren()) do
	if(v:IsA("Part")) then
	end
end

We check if v(the object) is indeed a part.(So it wont cause any problems if you have other things than parts in the model)

for i, v in pairs(gator:GetChildren()) do
	if(v:IsA("Part")) then
		v.Transparency = 1;
	end
end

Set the objects'(v's) transparency to 1.

workspace.Gator is a "Model" object. If you select it in the explorer, you will see that it does not have a Transparency property.

Different parts in a model can have different Transparency values (one can be invisible, one can be visible, one can be see-through), so the Model itself can't have one Transparency property.


workspace.Gator doesn't have a .Transparency property. But each of the Part objects in it does.

For example, you could do the following:

wait(10)
workspace.Gator.Head.Transparency = 1
workspace.Gator.Body.Transparency = 1
workspace.Gator.Tail.Transparency = 1

This will work, but it's also a lot of typing.


Models don't have a .Transparency property. So what is it that you mean when you wrote workspace.Gator.Transparency = 1? You mean that each of the parts in workspace.Gator should become transparent.

This means we have to do something for each part inside workspace.Gator. This calls for a for loop.


gatorParts = workspace.Gator:GetChildren()

gatorParts becomes a list of all of the objects (directly) inside the workspace.Gator model -- e.g., it has workspace.Gator.Head, workspace.Gator.Body, workspace.Gator.Tail inside of it.

For each of those things inside, we need to set the .Transparency. You can do this with a for loop:

gatorParts = workspace.Gator:GetChildren()
for index, part in pairs(gatorParts) do
	-- do this stuff FOR EACH `part` in `gatorParts`
	part.Transparency = 1
end

Be careful that if there is some other object inside of the Gator, like a Script, this will be a problem. :GetChildren() gives you a list of all objects inside the Model, not just the parts.

Thus some of the parts could actually not be parts. We have to check that they are parts before modifying part.Transparency (since a Script doesn't have a Transparency, you'd get the same error you got in the script you posted).

gatorParts = workspace.Gator:GetChildren()
for index, child in pairs(gatorParts) do
	if child:IsA("BasePart") then
		-- `child` is a "BasePart", meaning Part, WedgePart, SpawnLocation, etc.
		child.Transparency = 1
	end
end

It says transparency is not a valid member of model because you need to define the parts that is in the model and than change the parts transparency! Hope I Helped!

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