Loading Screen Asset Loader Not Working

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.

image


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)
2 Likes

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
1 Like

It isn’t a localscript though? It’s just a regular server script.

script.Parent.Value is an error

A TextLabel doesn’t have a .Value property.

TextLabel.Text would be a correct way to call a TextLabel

I suggest changing it, since it is a UI for the local player.

TextLabel has a child called “Value”, so there is no error.

I did it as PlayerAdded because I don’t want it to display every time they die, just when they join the game.

To fix this, turn off ResetOnSpawn in the ScreenGui.

Ah, thank you! So more like this?

local time = 0.1
script.Parent.Parent.Discord.Visible = false

while wait(math.random(0,1.5)) do
	local AssetsLeft = script.Parent.Text
	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

Oh darn, you’re right, I overlooked it too quickly! My apologies

Yes. Also, I provided other suggestions for your code in my first post.

Yes, I will be taking those suggestions for the script, thank you.

I seem to be getting an error on line 6; AssetsLeft.Value = AssetsLeft.Value - 1

Little nitpick, you should use task.wait(time) since it’s more efficient, modern and faster than wait(time).

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 :joy: I’m not a very experienced scripter, I mostly build.

1 Like

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.

I believe that’s my fault from earlier. I didn’t see the child called “Value”. So your script.Parent.Value was correct. My apologies.

That’s alright, and thank you.