What do you want to achieve?
To fix my GUI and the script
What is the issue?
the issue im having is that
when i spawn in the game with leaderboard gui
The Roblox Username with GUI
it keep like glitching for no reason
it like showing the visible Gui to my username gui as well
What solutions have you tried so far?
Changing new gui
Tried added some another script
didnt work any either of this
wait()
until game:IsLoaded()
local players = game:GetService("Players")
local runService = game:GetService("RunService")
local starterGui = game:GetService("StarterGui")
local teams = game:GetService("Teams")
local tweenService = game:GetService("TweenService")
local userInputService = game:GetService("UserInputService")
local screenGui = script:FindFirstAncestorWhichIsA("ScreenGui")
local uiToggle = true
local uiCellScale = screenGui.Ui.Main.ListHolder.UIGridLayout.CellSize.Y.Scale
screenGui.Enabled = true
while true do
local layoutOrder = 1
starterGui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, false)
for _, frame in pairs(screenGui.Ui.Main.ListHolder:GetChildren()) do
if (frame:IsA("Frame")) then
frame:Destroy()
end
end
for _, team in pairs(teams:GetTeams()) do
if team.Name ~= "UNIT" and #team:GetPlayers() > 0 then
local teamFrame = screenGui.Template.Team:Clone()
teamFrame.BackgroundColor3 = team.TeamColor.Color
teamFrame.LayoutOrder = layoutOrder
teamFrame.Name = string.format("[Team] %s", team.Name)
teamFrame.Parent = screenGui.Ui.Main.ListHolder
teamFrame.Visible = true
teamFrame.TeamName.Text = team.Name
for _, player:Player in pairs(team:GetPlayers()) do
if player.Team.Name ~= "UNIT" then
local playerFrame = screenGui.Template.Player:Clone()
playerFrame.LayoutOrder = layoutOrder
playerFrame.Name = string.format("[Player] %s", player.Name)
playerFrame.Parent = screenGui.Ui.Main.ListHolder
playerFrame.Visible = true
if player.Team == game.Teams.Mafia then
local mafia = game.ReplicatedStorage.Remotes.MafiaSystemFunction:InvokeServer("getplayermafiadataOTHER", player.UserId)
if mafia then
playerFrame.PlayerName.Text = mafia["MafiaName"].." - "..player.Name
end
else
playerFrame.PlayerName.Text = player.Name
end
local sub = player:WaitForChild('Values', 3):WaitForChild('Subdivision', 3)
if not sub then return end
if sub.Value and sub.Value ~= '' then
playerFrame:FindFirstChild('PlayerName').Text = sub.Value..' - '..player.Name
local color = Color3.new(1, 1, 1)
local realColor = color
if require(game:GetService('ReplicatedStorage'):FindFirstChild('Modules'):FindFirstChild('SubColors'))[sub.Value] then
realColor = require(game:GetService('ReplicatedStorage'):FindFirstChild('Modules'):FindFirstChild('SubColors'))[sub.Value]
end
playerFrame:FindFirstChild('PlayerName').TextColor3 = realColor
end
end
end
layoutOrder += 1
end
end
screenGui.Ui.Main.ListHolder.UIGridLayout.CellSize = UDim2.new(1, 0, 0, screenGui.Ui.Main.AbsoluteSize.Y * uiCellScale)
task.wait(0.8)
end
userInputService.InputBegan:Connect(function(input, gameProcessedEvent)
if not (gameProcessedEvent) then
if (input.KeyCode == Enum.KeyCode.Tab) then
uiToggle = not uiToggle
if (uiToggle) then
tweenService:Create(screenGui.Ui.Main, TweenInfo.new(1), {Position = UDim2.fromScale(0.995, 0.01)}):Play()
else
tweenService:Create(screenGui.Ui.Main, TweenInfo.new(1), {Position = UDim2.fromScale(0.995 + 0.5, 0.01)}):Play()
end
end
end
end)
I’m assuming that controls the custom leaderboard. Using a while true loop is gonna eat a lot of memory, maybe change it to update on specific events (e.g. player joining, player leaving, player team change)
Instead updating the leaderboard every second, you can just update the leaderboard when player added or left, + real programmers never use while loop expect some cases.
Just move the code inside the loop and make it inside a function called Update and do what i told you to and don’t forget to remove the loop because it’s loop code never reaches to InputBegan
wait()
until game:IsLoaded()
local players = game:GetService("Players")
local runService = game:GetService("RunService")
local starterGui = game:GetService("StarterGui")
local teams = game:GetService("Teams")
local tweenService = game:GetService("TweenService")
local userInputService = game:GetService("UserInputService")
local screenGui = script:FindFirstAncestorWhichIsA("ScreenGui")
local uiToggle = true
local uiCellScale = screenGui.Ui.Main.ListHolder.UIGridLayout.CellSize.Y.Scale
screenGui.Enabled = true
function Update()
local layoutOrder = 1
starterGui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, false)
for _, frame in pairs(screenGui.Ui.Main.ListHolder:GetChildren()) do
if (frame:IsA("Frame")) then
frame:Destroy()
end
end
for _, team in pairs(teams:GetTeams()) do
if team.Name ~= "UNIT" and #team:GetPlayers() > 0 then
local teamFrame = screenGui.Template.Team:Clone()
teamFrame.BackgroundColor3 = team.TeamColor.Color
teamFrame.LayoutOrder = layoutOrder
teamFrame.Name = string.format("[Team] %s", team.Name)
teamFrame.Parent = screenGui.Ui.Main.ListHolder
teamFrame.Visible = true
teamFrame.TeamName.Text = team.Name
for _, player:Player in pairs(team:GetPlayers()) do
if player.Team.Name ~= "UNIT" then
local playerFrame = screenGui.Template.Player:Clone()
playerFrame.LayoutOrder = layoutOrder
playerFrame.Name = string.format("[Player] %s", player.Name)
playerFrame.Parent = screenGui.Ui.Main.ListHolder
playerFrame.Visible = true
if player.Team == game.Teams.Mafia then
local mafia = game.ReplicatedStorage.Remotes.MafiaSystemFunction:InvokeServer("getplayermafiadataOTHER", player.UserId)
if mafia then
playerFrame.PlayerName.Text = mafia["MafiaName"].." - "..player.Name
end
else
playerFrame.PlayerName.Text = player.Name
end
local sub = player:WaitForChild('Values', 3):WaitForChild('Subdivision', 3)
if not sub then return end
if sub.Value and sub.Value ~= '' then
playerFrame:FindFirstChild('PlayerName').Text = sub.Value..' - '..player.Name
local color = Color3.new(1, 1, 1)
local realColor = color
if require(game:GetService('ReplicatedStorage'):FindFirstChild('Modules'):FindFirstChild('SubColors'))[sub.Value] then
realColor = require(game:GetService('ReplicatedStorage'):FindFirstChild('Modules'):FindFirstChild('SubColors'))[sub.Value]
end
playerFrame:FindFirstChild('PlayerName').TextColor3 = realColor
end
end
end
layoutOrder += 1
end
end
screenGui.Ui.Main.ListHolder.UIGridLayout.CellSize = UDim2.new(1, 0, 0, screenGui.Ui.Main.AbsoluteSize.Y * uiCellScale)
task.wait(0.8)
end
game.Players.PlayerAdded(Update)
game.Players.PlayerRemoving(Update)
userInputService.InputBegan:Connect(function(input, gameProcessedEvent)
if not (gameProcessedEvent) then
if (input.KeyCode == Enum.KeyCode.Tab) then
uiToggle = not uiToggle
if (uiToggle) then
tweenService:Create(screenGui.Ui.Main, TweenInfo.new(1), {Position = UDim2.fromScale(0.995, 0.01)}):Play()
else
tweenService:Create(screenGui.Ui.Main, TweenInfo.new(1), {Position = UDim2.fromScale(0.995 + 0.5, 0.01)}):Play()
end
end
end
end)
Luke @KSA_Developer said, use a seperate function to manage the updating. I’d suggest also using a coroutine. That way, the UserInputServics lines will still fire.
local Update = coroutine.create(function()
--replacing while true
while task.wait(0.8) do
--update code here
end
end)
coroutine.resume(Update)