Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
Dwayder 29
7 years ago

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

Log in to vote
0
Answered by
Uglypoe 557 Donator Moderation Voter
7 years ago

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

Ad

Answer this question