For some reason when a player rejoins the game really fast after fisrt join the gui doesnt display the values like the reputation or totaltokens mostly but the other ones sometimes too and it really only happens in public game not in studio is there a reason for this? i’ve tried numerous waiting methods none work
local RS = game:GetService("ReplicatedStorage")
local Player = Players.LocalPlayer
task.wait(2)
-- Wait for child objects with default wait time of 5 seconds
local Stats = Player:WaitForChild("PhysicalStats", 3)
local Multis = Player:WaitForChild("Multipliers", 3)
local ReputationFolder = Player:WaitForChild("ReputationFolder", 3)
local CurrencyFolder = Player:WaitForChild("Currency", 3)
local MultiFrame = script.Parent.Parent:WaitForChild("MultiFrame", 3)
local MultiInfo = MultiFrame and MultiFrame:WaitForChild("InfoText", 3)
local Modules = RS:WaitForChild("Modules", 3)
local MultiModule = Modules and require(Modules:WaitForChild("Multis", 3))
-- Abbreviation Function
local function abbreviateNumber(num)
num = tonumber(num)
if not num then return "Invalid" end
local abbreviations = {
{1e63, "Vg"},
{1e60, "Nod"},
{1e57, "Ocd"},
{1e54, "Spd"},
{1e51, "Sxd"},
{1e48, "Qui"},
{1e45, "Qua"},
{1e42, "Td"},
{1e39, "Dd"},
{1e36, "Ud"},
{1e33, "Dc"},
{1e30, "N"},
{1e27, "Oc"},
{1e24, "Sp"},
{1e21, "Sx"},
{1e18, "Qi"},
{1e15, "Qa"},
{1e12, "T"},
{1e9, "B"},
{1e6, "M"},
{1e3, "K"}
}
for i = 1, #abbreviations do
local factor, suffix = unpack(abbreviations[i])
if num >= factor then
local formattedNumber = num / factor
if formattedNumber % 1 == 0 then
return string.format("%d%s", formattedNumber, suffix)
else
return string.format("%.2f%s", formattedNumber, suffix)
end
end
end
return string.format("%d", num)
end
-- Initialize total tokens earned value
local totalTokensEarned = 0
local previousTokenAmount = 0
-- Update Total Power Display
local function updateTotalPowerDisplay()
local totalPowerFrame = script.Parent:WaitForChild("Total Power", 3)
if totalPowerFrame then
local totalPowerDisplay = totalPowerFrame:WaitForChild("TotalPowerDisplay", 3)
local totalPower = Stats:WaitForChild("TotalPower", 3)
if totalPowerDisplay and totalPower then
totalPowerDisplay.Text = "Total Power: " .. abbreviateNumber(tonumber(totalPower.Value) or 0)
end
end
end
-- Update Player's Name Display
local function updatePlayersNameDisplay()
local playersNameFrame = script.Parent:WaitForChild("Players Name", 3)
if playersNameFrame then
local playersNameDisplay = playersNameFrame:WaitForChild("PlayersNameDisplay", 3)
if playersNameDisplay then
playersNameDisplay.Text = "Name: " .. Player.Name
end
end
end
-- Update Reputation Display
local function updateReputationDisplay()
local reputationFrame = script.Parent:WaitForChild("Reputation", 3)
if reputationFrame then
local reputationDisplay = reputationFrame:WaitForChild("ReputationDisplay", 3)
local reputationValue = ReputationFolder:WaitForChild("Reputation", 3)
if reputationDisplay and reputationValue then
reputationDisplay.Text = "Reputation: " .. abbreviateNumber(tonumber(reputationValue.Value) or 0)
end
end
end
-- Update Total Tokens Earned Display
local function updateTotalTokensDisplay()
local totalTokensFrame = script.Parent:WaitForChild("Total Tokens Earned", 3)
if totalTokensFrame then
local totalTokensDisplay = totalTokensFrame:WaitForChild("TotalTokensEarnedDisplay", 3)
local totalTokensStat = CurrencyFolder:WaitForChild("TotalTokens", 3)
if totalTokensDisplay and totalTokensStat then
-- Display the TotalTokens value
totalTokensDisplay.Text = "Total Tokens Earned: " .. abbreviateNumber(totalTokensStat.Value)
else
print("TotalTokens not found in Currency folder.")
end
end
end
-- Update UI elements for each stat frame
for _, Frame in script.Parent:GetChildren() do
if Frame:IsA("Frame") then
local statName = string.split(Frame.Name, ' ')[1]
local stat = Stats:WaitForChild(statName, 3)
if stat then
local Multi = Multis:WaitForChild(statName.."Multi", 3)
local statValue = stat.Value
Frame:WaitForChild("StatDisplay", 3).Text = statName..": "..abbreviateNumber(statValue)
stat.Changed:Connect(function()
local newStatValue = stat.Value
Frame:WaitForChild("StatDisplay", 3).Text = statName..": "..abbreviateNumber(newStatValue)
updateTotalPowerDisplay()
end)
local multiDisplay = Frame:WaitForChild("MultiDisplayGui", 3)
if multiDisplay then
multiDisplay.Text = "x"..abbreviateNumber(Multi.Value)
Multi.Changed:Connect(function()
multiDisplay.Text = "x"..abbreviateNumber(Multi.Value)
end)
end
Frame:WaitForChild("MultiButton", 3).MouseButton1Click:Connect(function()
local Price = MultiModule.GetNextMultiData(Multi)[2]
MultiInfo.Text = "Your current multiplier is x"..abbreviateNumber(Multi.Value).." would you like to upgrade to x"..abbreviateNumber(Multi.Value*2).." for "..abbreviateNumber(Price).." tokens?"
MultiFrame.Visible = true
MultiFrame.CurStat.Value = statName
end)
end
end
end
-- Initial setup
updateTotalPowerDisplay()
updatePlayersNameDisplay()
updateReputationDisplay()
updateTotalTokensDisplay()
-- Update Reputation Display when Reputation changes
local Reputation = ReputationFolder:WaitForChild("Reputation", 5)
if Reputation then
Reputation.Changed:Connect(updateReputationDisplay)
else
print("Reputation not found in ReputationFolder.")
end
-- Update Total Tokens Earned Display when Tokens change
local Tokens = CurrencyFolder:WaitForChild("Tokens", 5)
if Tokens then
Tokens.Changed:Connect(updateTotalTokensDisplay)
else
print("Tokens not found in CurrencyFolder.")
end