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

How to fix this Transparency changing manican script?

Asked by 8 years ago

This script is just for me to learn more lua and i am trying to get every part on the manican to change transparency after 1 second every time

Dummy = script.Parent:GetChildren()

function ghost()
    wait(1)
    Dummy.Transparency = 0.1
    wait(1)
    Dummy.Transparency = 0.2
    wait(1)
    Dummy.Transparency = 0.3
    wait(1)
    Dummy.Transparency = 0.4
    wait(1)
    Dummy.Transparency = 0.5
    wait(1)
    Dummy.Transparency = 0.6
    wait(1)
    Dummy.Transparency = 0.7
    wait(1)
    Dummy.Transparency = 0.8
    wait(1)
    Dummy.Transparency = 0.9
end

game.Players.PlayerAdded:connect(ghost)

Also any way to shorten a Transparency script like this with time?

Please help me explain just a bit so i can understand the method you use :)

1 answer

Log in to vote
3
Answered by
Pyrondon 2089 Game Jam Winner Moderation Voter Community Moderator
8 years ago

For loops. Not only will they make it work, they'll also shorten it. Two birds, one loop.

Or two, in this case.

local Dummy = script.Parent:GetChildren()

function ghost()
    for i = .1, .9, .1 do --// The first number is what 'i' is initially set to. The second is the number it ends on, and the third is the increment (what it changes by after each iteration).
        wait(1)
        for _, child in pairs(Dummy) do --// We don't need the index, so we use the placeholder (_).
            child.Transparency = i
        end
    end
end

game.Players.PlayerAdded:connect(ghost)

Hope this helped.

1
Ehhh, I could do better. User#11440 120 — 8y
0
Pfft, you wish Pyrondon 2089 — 8y
Ad

Answer this question