I wrote a script for an asset loader, but for some reason it is not working. I have no errors, it just says “Assets Loading,” but never displays the numbers like it is supposed to. Normally it will say “Assets Loading [number here],” but it isn’t. Code & hierarchy below.
local time = 0.1
script.Parent.Parent.Discord.Visible = false
game.Players.PlayerAdded:Connect(function()
while wait(math.random(0,1.5)) do
local AssetsLeft = script.Parent.Value
AssetsLeft.Value = AssetsLeft.Value - 1
script.Parent.Text = "Loading Assets ["..AssetsLeft.Value.."]"
if AssetsLeft.Value == 0 then
script.Parent.Text = "Done!"
wait(2.5)
script.Parent.Transparency = 0.1
wait(time)
script.Parent.BackgroundTransparency = 1
script.Parent.Transparency = 0.2
wait(time)
script.Parent.BackgroundTransparency = 1
script.Parent.Transparency = 0.3
wait(time)
script.Parent.BackgroundTransparency = 1
script.Parent.Transparency = 0.4
wait(time)
script.Parent.BackgroundTransparency = 1
script.Parent.Transparency = 0.5
wait(time)
script.Parent.BackgroundTransparency = 1
script.Parent.Transparency = 0.6
wait(time)
script.Parent.BackgroundTransparency = 1
script.Parent.Transparency = 0.7
wait(time)
script.Parent.BackgroundTransparency = 1
script.Parent.Transparency = 0.8
wait(time)
script.Parent.BackgroundTransparency = 1
script.Parent.Transparency = 0.9
wait(time)
script.Parent.BackgroundTransparency = 1
script.Parent.Transparency = 1
wait(time)
script.Parent.BackgroundTransparency = 1
script.Parent.Visible = false
if script.Parent.Visible == false then
script.Parent.Parent.Discord.Visible = true
end
end
end
end)
The problem here is that PlayerAdded won’t fire upon the player themselves joining. Since this is a LocalScript, you can just exclude the PlayerAdded function.
A few other things about your code:
When waiting random decimals, math.random(x,y) only selects integers. Instead, do math.random()*1.5.
TweenService can be used to smoothly change any value in different styles, and is a lot easier and more efficient to use than what you are currently doing
Edit:
“time” is a default variable, so I suggest changing the name of your time increment value
How so? I don’t see how you can make it “more efficient,” wouldn’t it be doing the same thing anyways? By all means, disregard that I’m not a very experienced scripter, I mostly build.
It behaves similar to RunService.Heartbeat instead of general time which is faster, while wait(time) is slower, less accurate to real time and going to be deprecated soon.