For ipairs isnt working for BasePart transparency

Hey guys and gals, today I have a problem. Again! I was trying to script something that when you touch a part, it will delete a tool in your inventory and then show a model. I got up to the point where it would remove the tool, but I haven’t been able to put transparency to 1 on all the baseparts in the model.

In short, when you touch a part, it should find the models children and then change the transparency to 0 on all of them (Making them visible.)

like this:

My script is as follows:

	local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
	if player then
		local backpack = player:FindFirstChild("Backpack")
		if backpack then
			local flower =backpack:FindFirstChild("Flower")
			if flower then
				--print("Found flower")
				local children = workspace.StaticFlower1:GetChildren()
				for i, child in ipairs(children) do
					if child:IsA("Part") then

I put a few print statements in, but the only one that prints is the first one, which prints the parent of the player variable.

Why don’t you use for in pairs Also check if it’s a basepart

	for i, child in pairs(children) do
					if child:IsA("BasePart") then

Are they the same thing? And I was checking if the child is a BasePart

You were checking if it’s a Part
BasePart = a Part or a Mesh.

ipairs() is used with arrays
pairs() works with dictionaries
Did it work?
Am I missing something?


pairs() returns key-value pairs and is mostly used for associative tables. key order is unspecified. pairs() returns index-value pairs and is mostly used for numeric tables .

1 Like

I don’t think you need to use FindFirstChild on the backpack as that is always loaded on the player, so remove that if statement to remove some indentation.

The only other thing I think it could be is that you may be holding the flower when testing? If you hold a tool, it gets parented to the character, so also check if the player’s character has Flower

local flower = player.Character:FindFirstChild("Flower") or backpack:FindFirstChild("Flower")

also if you want o ensure all the parts become visible, change "Part" to "BasePart" and instead of GetChildren use GetDescendants


I have a question what’s the difference between basePart and part and what is GetDescendants? ive never used getDescendants

Basepart basically is a MeshPart or a Part
Part is basically the a Part or a brick

Now for GetDescendants

Lets Say Model:GetDescendants()
It will get the Children of the Model
And the Children of the Part of the Model.


wow instead of getdescendants() ive been going model:getchildren():getchildren() I must go fix some code

Thank you!!! I’m an idiot for not knowing that? But when the player is using a tool (has it in the hand,) does it get moved or does it get cloned?

1 Like

It gets reparented to player’s character model.