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
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.
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