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

How to Remove the GUI Automatically?

Asked by 10 years ago

I Created a Loading Bar (GUI) and i don't know how to Remove the GUI automatically with script.

Here's my Written Code in the LocalScript.

for i = 0,100,1 do
script.Parent.DataLoader.Text = "Data Loaded: " .. math.floor(i) .. "%"
script.Parent.Loader.Size = UDim2.new(0, i*5, 0, 50)
wait(math.random(0.13,0.12)) 
end

2 answers

Log in to vote
1
Answered by 10 years ago

You can do two things, you can either remove the GUI using the :Destroy() function, or hide it by setting the Visible property to false. The second is preferable so you don't have to recreate the GUI. I've also fixed and commented some other oddities in the snippet you've provided.

-- Loops should start at 1, otherwise it'll run 101 times instead of 100. The step is 1 by default, so you don't need to provide it here.
for i = 1,100 do
    -- the math.floor() isn't needed as the number will always be an integer.
    script.Parent.DataLoader.Text = "Data Loaded: " .. i .. "%"
    script.Parent.Loader.Size = UDim2.new(0, i*5, 0, 50)

    -- the math.random() function can only take integers. When given nothing, it will return a decimal number from 0 to 1, and you need to do some simple math to get the range you want. The simpler option is just using a set number between each loop, since the difference of 0.12 to 0.13 is miniscule.
    wait(0.12) 
end

I'll also add that fake loading bars don't do much for the experience other than annoy the player, so I'd recommend against using one.

0
I Rewrite again the Code and i change the code to your code you provided. But im asking how to remove it using the :destroy() or function. you should post the code runny21 5 — 10y
Ad
Log in to vote
2
Answered by 10 years ago

You could try this, the wait is probably messing it up a bit since the larger number is first and not last.

for i = 0, 100, 1 do
    script.Parent.Data.Loader.Text = "Data Loaded: "..i.."%"
    script.Parent.Loader.Size = UDim2.new(0, i*5, 0 50)
    wait(math.random(.1, .15))
end

Answer this question