Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I make a script for a model to make its transparency decrease smoothly?

This is what I've tried.

local model = script.Parent
local baseParts = {}

local findAllBasePartsDescendants = function(parent)
    for k, v in pairs(parent:GetChildren()) do
        if v:IsA("BasePart") then
            table.insert(baseParts, v)
        end
        findAllBasePartsDescendants(v) -- It gives me an error at this line. (unknown global)
    end
end

findAllBasePartsDescendants(model)

for k, v in pairs(baseParts) do
    if v.Transparency > 0 then
        v.Transparency = v.Transparency - 0.05
    end
    wait()
end

I'm trying to make a model decrease in transparency smoothly. This is a normal script in the model, which has only 5 parts..

1 answer

✓ Accepted answer

Your issue seems to be that you're trying to call a function within itself. While this is possible, the variable you call has to be created before the function is created in order to execute properly. I've fixed it below:

local model = script.Parent
local baseParts = {}

local findAllBasePartsDescendants
findAllBasePartsDescendants = function(parent)
    for k, v in pairs(parent:GetChildren()) do
        if v:IsA("BasePart") then
            table.insert(baseParts, v)
        end
        findAllBasePartsDescendants(v)
    end
end

findAllBasePartsDescendants(model)

for k, v in pairs(baseParts) do
    if v.Transparency > 0 then
        v.Transparency = v.Transparency - 0.05
    end
    wait()
end

If you need any more help, feel free to ask! -Poe

This discussion is preserved as it was. New answers, comments, and votes are closed.