I don’t know if this is the right place to ask this. But I am working on an optimized loading screen which is made by a script. The script creates all the GUI elements, but that leaves an issue. By creating the elements with the script, I find that the elements don’t fit most screens.
Is there any way I can constraint or make the GUI elements fit the screen without adding a constraint? Or, how can I constraint the GUI elements using the script?
Here is the code for the loading screen. There are no errors, but I thought it might help out somehow.
--[[
|| Script Name: Loading
|| Script Type: Executable
|| Written by: @NolanCYT
|| Version 1.0
|| Description: Loads the game
|| This LocalScript will create a ScreenGui to cover the game while all assets and data are loaded in.
|| To disable script, simply change the boolean "LoadGame" to false.
|| And vice versa to enable game loading.
]]
--[Data]
local t = true
local f = false
local LoadGame = t
--[Services]
local ContentProvider = game:GetService("ContentProvider")
local Players = game:GetService("Players")
local ReplicatedFirst = game:GetService("ReplicatedFirst")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local StarterGui = game:GetService("StarterGui")
local TweenService = game:GetService("TweenService")
--[Variables]
local Player = Players.LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")
local UserID = Player.UserId
local Assets = ReplicatedStorage:WaitForChild("Assets")
local Audio = require(Assets:WaitForChild("Audio"))
local DevProducts = require(Assets:WaitForChild("DevProducts"))
local Images = require(Assets:WaitForChild("Images"))
local Animations = require(Assets:WaitForChild("Animations"))
local Places = require(Assets:WaitForChild("Places"))
function create(instanceType)
return function(data)
local Object = Instance.new(instanceType)
for a, b in pairs(data) do
local c, d = pcall(function()
if type(a) == 'number' then b.Parent = Object
elseif type(b) == 'function' then Object[a]:connect(b)
else Object[a] = b end
end)
if not c then
error('ERROR: Applying property, '..a..', to '..instanceType..' failed! ('..d..')')
end
end
return Object
end
end
--[[
||Checkpoint #1
--
||Creating Loading GUI, Preloading Images and Audio
--]]
if LoadGame ~= t then script:Destroy() end
local Gui = Instance.new("ScreenGui")
Gui.Name = "LoadingGui"
Gui.IgnoreGuiInset = t
Gui.Parent = PlayerGui
local Background = create 'Frame' {
BackgroundColor3 = Color3.new(0.0,0.0,0.0),
BorderSizePixel = 0,
Size = UDim2.new(1.0,0,1.0,0),
Position = UDim2.new(0.0,0,0.0,0),
Parent = Gui
}
ReplicatedFirst:RemoveDefaultLoadingScreen()
--[Buffer]
task.wait(3)
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All,f)
local AssetNumber = create 'TextLabel' {
BackgroundTransparency = 1.0,
Size = UDim2.new(1.0,0,0.0,40),
Position = UDim2.new(0.0,0,0.0,40),
TextXAlignment = Enum.TextXAlignment.Left,
Font = Enum.Font.Arcade,
TextScaled = true,
TextColor3 = Color3.new(1, 1, 1),
ZIndex = 2,
Parent = Background,
}
--[Counting the Assets/Buffer]
local a = 1
for _, assets in pairs(Images) do
a = a + 1 AssetNumber.Text = ("("..a..")")
task.wait(math.random(0.01,0.06))
end
AssetNumber:Remove()
--[Buffer]
task.wait(1)
--[Load Images]
local function PreloadFailed(contentId,Status)
if Status == Enum.AssetFetchStatus.Failure then
warn("Failed to load "..tostring(contentId))
end
end
local StatusLabel = create 'TextLabel' {
BackgroundTransparency = 1.0,
Size = UDim2.new(1.0,0,0.0,40),
Position = UDim2.new(0.0,0,0.0,40),
TextXAlignment = Enum.TextXAlignment.Left,
Font = Enum.Font.Arcade,
TextScaled = true,
TextColor3 = Color3.new(1.0,1.0,1.0),
ZIndex = 2,
Parent = Background,
}
--[Preload Images]
StatusLabel.Text = "Loading Images..."
for _, image in pairs(Images) do
ContentProvider:PreloadAsync({image},PreloadFailed)
end
--[Preload Audio]
StatusLabel.Text = "Loading Audio..."
for _, audio in pairs(Audio) do
ContentProvider:PreloadAsync({audio},PreloadFailed)
end
--[Preload Animations]
StatusLabel.Text = "Loading Animations..."
for _, animation in pairs(Animations) do
ContentProvider:PreloadAsync({animation},PreloadFailed)
end
local LoadingIcon1 = create 'ImageLabel' {
BackgroundTransparency = 1.0,
Image = Images.LoadingCheckpoint,
ImageColor3 = Color3.new(1.0,1.0,0.0),
Size = UDim2.new(0.0,100,0.0,100),
Position = UDim2.new(1.0-0.1,0,1.0-0.2,0),
ZIndex = 1,
Parent = Background,
}
This is what the gui elements look like in studio.
Here’s what it looks like with an emulator.
So it wouldn’t fit most screens. Any help will do. Thanks!