I’m trying to create a system where a model disappears for a set period of time once clicked, but I’m puzzled on what line of code to use. I believe it has something to do with GetChildren or ‘in pairs do’.
Here’s the code I’ve written:
local Flashlight = game.ServerStorage.Lighter
local clickable = true
script.Parent.ClickDetector.MouseClick:Connect(function(player)
if clickable then
local Find = player.Backpack:FindFirstChild("Lighter")
if not Find then
clickable = false
script.Parent.ClickDetector.MaxActivationDistance = 0
Flashlight:Clone().Parent = player.Backpack
wait(30)
script.Parent.ClickDetector.MaxActivationDistance = 10
clickable = true
end
end
end)
And here’s a screenshot of all the parts in that Model:
If any of you could help me with finding a simple line of code to use to make every part in StaticLighter transparent, I would much appreciate it. Thanks!
local model = -- your model (script.Parent.Parent in your current case)
local descendants = model:GetDescendants() -- you can use :GetChildren() if there are not BaseParts parented to another BasePart
for i=1,#descendants do
local descendant = descendants[i]
if descendant:IsA("BasePart") then
descendant.Transparency = 1
end
end
Hey, this code worked great as I need a model to disappear when I click on it. However, it seems that the decal on the model doesn’t turn transparent. Everything goes as scripted except the decal. Any idea on how to script a decal to become invisible?
The decal isn’t a BasePart so it’s not turning transparent. You would need to change if descendant:IsA("BasePart") then
in order to also have the decal become transparent.
local model = -- your model (script.Parent.Parent in your current case)
local descendants = model:GetDescendants() -- you can use :GetChildren() if there are no BaseParts parented to another BasePart
for i=1,#descendants do
local descendant = descendants[i]
if descendant:IsA("BasePart") or descendant:IsA("Decal") then
descendant.Transparency = 1
end
end
Only difference is that you’re looking for the decals inside the model, along with baseparts “or descendant:IsA(“Decal”)”