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.)
script.Parent.Touched:Connect(function(hit)
local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if player then
print(player.Parent)
local backpack = player:FindFirstChild("Backpack")
if backpack then
local flower =backpack:FindFirstChild("Flower")
if flower then
print("Flower")
flower:Destroy()
--print("Found flower")
local children = workspace.StaticFlower1:GetChildren()
for i, child in ipairs(children) do
if child:IsA("Part") then
child.Transparency=0
end
end
end
end
end
end)
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.
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 .
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