So, I’m making a keycard system, and I want to select the children in the model, as Model doesn’t have Transparency or CanCollide. So, I tried to make a system to select the children, but it failed. I need to have the door as a model, as in unions, the decals, and materials don’t save.
script.Parent.Touched:Connect(function(hit)
if hit.Parent.Name == "Keycard" then
workspace.Door1:getChildren("CanCollide", false)
workspace.Door1:getChildren("Transparency", 1)
wait(1)
workspace.Door1:getChildren("CanCollide", true)
workspace.Door1:getChildren("Transparency", 0)
end
end)
:GetChildren() is a function that returns all children of an instance into a table.
Anyways, to get the values inside a table, you have to use pairs loop.
script.Parent.Touched:Connect(function(hit)
if hit.Parent.Name == "Keycard" then
for _,v in pairs(workspace.Door1:GetChildren()) do
if v:IsA("BasePart") then
--makes your part invisible
--remember, "v" is the part
--v.Transparency = 1
--v.CanCollide = false
--wait(1)
--v.Transparency = 0
--v.CanCollide = true
end
end
end
end)
Anyways, the solution bacon guy give is the right one
This happened, I’m not sure what is going wrong in the script. It’s really weird. https://gyazo.com/60b55b9ed89f9f752bb8bacce8c735cf
The gif may be a bit laggy, sorry for that! I’ll try Nerk’s script and see if the same thing happens.
You will need to do for loop, where you make them Transprent and not Collidable
Then outside of the loop, do wait(1) and then loop with making then normal again.
script.Parent.Touched:Connect(function(hit)
if hit.Parent.Name == "Keycard" then
for _,v in pairs(workspace.Door1:GetChildren()) do
if v:IsA("BasePart") then
--makes your part invisible
--remember, "v" is the part
v.Transparency = 1
v.CanCollide = false
end
end
wait(1)
for _,v in pairs(workspace.Door1:GetChildren()) do
if v:IsA("BasePart") then
--makes your part invisible
--remember, "v" is the part
v.Transparency = 0
v.CanCollide = true
end
end
end
end)
litteraly what this guy aboves says
if you put wait(1) inside the loop, it will make the the parts go invisible and visible one by one,
so you have to make a loop to where it becomes invisible
and wait(1)
and make another loop where it becomes visible again
Also,
@Barothoth I don’t quite understand the different, can you tell me so I can get some extra information uwu
I think that GetDescendants is basically like GetChildren, but it selects more parts in the model? I think that’s what he means. That’s at least what I think he said.
GetDescendants is a recursive function where it checks all children in the object, and all the children of those children, and all the children of those children, and so forth until their is nothing left. If we are still checking for base part, that means when are selecting every part in the model no matter how complex the model is.
If only I could make all of your responses solutions because you guys really helped me out! I was thinking on just making the door a singular part and it’d make it look bland and uninteresting.