I made a script for a loading screen and it doesn’t seem to work. It stays at zero percent and only seems to loop once. Can somebody explain what’s wrong?
game.ReplicatedFirst:RemoveDefaultLoadingScreen()
local player = game.Players.LocalPlayer
local loadCoro = coroutine.create(function()
local percentage = 0
while true do
player:WaitForChild("PlayerGui").LoadingScreen.MainFrame.Text.Text = "Loading: " .. percentage .. "%"
print(percentage/100)
player:WaitForChild("PlayerGui"):WaitForChild("LoadingScreen").MainFrame.Background.Green.Size.X.Scale = percentage/100
percentage+=1
wait(.1)
end
end)
local PlayerGui = game.Players.LocalPlayer:WaitForChild("PlayerGui")
local GUI = script.LoadingScreen:Clone()
GUI.Parent = PlayerGui
coroutine.resume(loadCoro)
Coroutines do not report errors to log, you are attempting to set the scale of a UI element to a number, it must be set via UDim2().
local ReplicatedFirst = game:GetService("ReplicatedFirst")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local playergui = player:WaitForChild("PlayerGui")
local loadscreen = playergui:WaitForChild("LoadingScreen")
ReplicatedFirst:RemoveDefaultLoadingScreen()
local loadCoro = coroutine.create(function()
local percentage = 0
while true do
playergui.LoadingScreen.MainFrame.Text.Text = "Loading: " .. percentage .. "%"
print(percentage/100)
loadscreen.MainFrame.Background.Green.Size = UDim2.new(percentage/100, XPixels, YScale, YPixels)
percentage+=1
wait(0.1)
end
end)
local GUI = script.LoadingScreen:Clone()
GUI.Parent = playergui
coroutine.resume(loadCoro)
I have also corrected some bad scripting practices.
You will need to change XPixels, YScale, etc. to what they are of your green bar.
I fixed it because it wasn’t exactly working how you had it:
local ReplicatedFirst = game:GetService("ReplicatedFirst")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local playergui = player:WaitForChild("PlayerGui")
local loadscreen = script.LoadingScreen:Clone()
loadscreen.Parent = playergui
ReplicatedFirst:RemoveDefaultLoadingScreen()
local loadCoro = coroutine.create(function()
local percentage = 0
while true do
playergui.LoadingScreen.MainFrame.Text.Text = "Loading: " .. percentage .. "%"
print(percentage/100)
loadscreen.MainFrame.Background.Green.Size = UDim2.new(percentage/100, 0, 1, 0)
percentage+=1
wait(0.1)
end
end)
coroutine.resume(loadCoro)