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

Trying to do the math of a asset loading bar, help?

Asked by
hudzell 238 Moderation Voter
10 years ago

So I am trying to make a bar that calculates how many assets in a table there are to load and then every asset the bar progresses the correct amount. How would I do this? Here is the script:

game.Players.PlayerAdded:connect(function(plr)
    local gui = script.Welcome:Clone()
    gui.Parent = plr.PlayerGui
    local sound = gui.Sound
    repeat wait() until plr.Character
    plr.Character:remove()
    wait(3)
    wait(.2)
    assets = {147183919,131326340,154904310}
    asse = 1
    for _, asset in ipairs(assets) do
        local m = #assets
        local bar = gui.Background.Progress.Bar
        gui.Background.Preload.Text = "Preloading asset "..asset.." ("..asse.."/"..m..")"
        game:GetService("ContentProvider"):Preload("http://www.roblox.com/asset/?id=" .. asset)
        bar.Size = UDim2.new() --Trying to put it here, but I have no idea how to do the math
        asse = asse + 1
        wait(.3)
    end
    gui.Background.Preload.Text = "Done"
    for i = 1,10 do
        gui.Background.Preload.TextTransparency = gui.Background.Preload.TextTransparency + .1
        wait(.01)
    end
    wait(1.5)
    gui.Background.Preload:remove()
    wait(1)
    gui.Background.Message.Visible = true
    sound:Play()
    wait(1)
    gui.Background.Secondary.Text.Visible = true
    sound:Play()
    wait(1)
    gui.Background.Secondary.NameG.Visible = true
    sound:Play()
    wait(1)
    gui.Background.Scripted.Text.Visible = true
    gui.Background.Scripted.NameG.Visible = true
    sound:Play()
    wait(2)
    for i = 1,10 do
        gui.Background.Message.TextTransparency = gui.Background.Message.TextTransparency + .1
        gui.Background.Message.TextStrokeTransparency = gui.Background.Message.TextStrokeTransparency + .1
        gui.Background.Secondary.NameG.TextTransparency = gui.Background.Secondary.NameG.TextTransparency + .1
        gui.Background.Secondary.NameG.TextStrokeTransparency = gui.Background.Secondary.NameG.TextStrokeTransparency + .1
        gui.Background.Secondary.Text.TextTransparency = gui.Background.Secondary.Text.TextTransparency + .1
        gui.Background.Secondary.Text.TextStrokeTransparency = gui.Background.Secondary.Text.TextStrokeTransparency + .1
        gui.Background.Scripted.Text.TextTransparency = gui.Background.Secondary.Text.TextTransparency + .1
        gui.Background.Scripted.Text.TextStrokeTransparency = gui.Background.Secondary.Text.TextStrokeTransparency + .1
        gui.Background.Scripted.NameG.TextTransparency = gui.Background.Secondary.Text.TextTransparency + .1
        gui.Background.Scripted.NameG.TextStrokeTransparency = gui.Background.Secondary.Text.TextStrokeTransparency + .1
        wait(.1)
    end
    plr:LoadCharacter()
    local gui = script.Welcome:Clone()
    gui.Parent = plr.PlayerGui
    gui.Background.Preload:remove()
    wait(1)
    for i = 1,100 do
        gui.Background.BackgroundTransparency = gui.Background.BackgroundTransparency + .01
        wait(.01)
    end
    gui:remove()
end)

1 answer

Log in to vote
0
Answered by
Nickoakz 231 Moderation Voter
10 years ago

Could this be your code?

for num, asset in ipairs(assets) do
        local m = #assets
        local bar = gui.Background.Progress.Bar
        gui.Background.Preload.Text = "Preloading asset "..asset.." ("..num.."/"..m..")"
        game:GetService("ContentProvider"):Preload("http://www.roblox.com/asset/?id=" .. asset)
        bar.Size = UDim2.new(a/num,0,1,0) --Try it?
        wait(.3)
    end

This is not your answer, but I just can't stop looking at that nasty code you had..

    for i = 0,1,.1 do
        gui.Background.Message.TextTransparency = i
        gui.Background.Message.TextStrokeTransparency = i
        gui.Background.Secondary.NameG.TextTransparency = i
        gui.Background.Secondary.NameG.TextStrokeTransparency = i
        gui.Background.Secondary.Text.TextTransparency = i
        gui.Background.Secondary.Text.TextStrokeTransparency = i
        gui.Background.Scripted.Text.TextTransparency = i
        gui.Background.Scripted.Text.TextStrokeTransparency = i
        gui.Background.Scripted.NameG.TextTransparency = i
        gui.Background.Scripted.NameG.TextStrokeTransparency = i
        wait(.1)
    end
0
Thanks! I used both of the code you provided, the math was a bit wrong thought, I did num/m instead of a/num hudzell 238 — 10y
Ad

Answer this question