Hiii! I’m using this script for when you click on a button the model transparency is 1, but it doesn’t work. Can someone help?
When I’m playing I can’t see anything, and when I find it and click it nothing happens.
Hiii! I’m using this script for when you click on a button the model transparency is 1, but it doesn’t work. Can someone help?
When I’m playing I can’t see anything, and when I find it and click it nothing happens.
use a in pairs loop instead of that
Well, your biggest problem is the fact that you didn’t put that code in a .MouseClick event.
Here’s what you would do:
local clickPart = script.Parent
local clickDetector = clickPart.ClickDetector
local transparent = false
local function makeTransparent()
transparent = not transparent -- for an easy toggle
for _, obj in ipairs(clickPart.Parent:GetDescendants()) do
if obj ~= clickPart then
if obj.Transparency then
obj.Transparency = (transparent and 1 or 0) -- ternary statement basically functions the same as: if transparency then obj.Transparency = 1 else obj.Transparency = 0 end
end
end
end
end
clickDetector.MouseClick:Connect(makeTransparent)
Does it work with models as well?
I’d imagine so, yes. Could be wrong, I haven’t tested it yet. It’s meant to work with your displayed project structure.
I checked now and it doesn’t work with models what do I need to change/ add?
Think of inheritance like a table. If we have base parts in folders which are inherited by this parent we cant just index them, cause then will go out of bounds giving us nil every single time. The solution? Enumerate it with for i,v in pairs()
So the script should look like this?
local clickPart = script.Parent local clickDetector = clickPart.ClickDetector local transparent = false local function makeTransparent() transparent = not transparent -- for an easy toggle for i,v in pairs(), obj in ipairs(clickPart.Parent:GetDescendants()) do if obj ~= clickPart then if obj.Transparency then obj.Transparency = (transparent and 1 or 0) -- ternary statement basically functions the same as: if transparency then obj.Transparency = 1 else obj.Transparency = 0 end end end end end clickDetector.MouseClick:Connect(makeTransparent)
I dont think you can represent conditional operators in variables… Other than that I don’t understand this for loop syntax. It is for index, value in pairs(clickPart.Parent:GetDescendants())
I’m not really sure what I need but thanks!
Try this
local gal = script.Parent.Parent
local allpart = script.Parent:GetChildren()
local function onclick()
for i,v in pairs(allpart) then
If v:IsA("Part") then
v.Transparency = 0
end
end
end)
gal.ClickDetector.MouseButton1Down:Connect(Onclick)
Try this just find out the click detector lol
that makes it not transparent, that makes it fully seeable