So I created a Leaderboard and corresponding scripts for my games two GUI's to populate the information that is required to use my game. When I play the Game in Studio it is brilliant, everything works great and it loads fast. However when I publish the game to Roblox , and proceed to try and play the game It does not load either of the GUI's. Let me try and break this down so its a bit more simple.

                                                            GUI 1

shows the players level on the top with a progress bar on the bottom to show how much experience the player has to go to progress to the next level. This Has Two Scripts to make it work, 1 for the players level and a second for the progress bar.

This first Script is for the Get Level


local player = game.Players.LocalPlayer
local level = player:WaitForChild("leaderstats"):WaitForChild("Level")
 
script.Parent.Text = "Current Level: " .. level.Value
 
level.Changed:Connect(function(value)
    script.Parent.Text = "Current Level: " .. value
end)
                                                

The Second Script Is for my ExpBar Animation

local player = game.Players.LocalPlayer
local exp = player:WaitForChild("leaderstats"):WaitForChild("Exp")
local axp = player:WaitForChild("leaderstats"):WaitForChild("ExpNeeded")
 
while true do
    wait()
    local expBarSize = (exp.Value/axp.Value) - 0.02
    if exp.Value == 0 then
        expBarSize = 0
        script.Parent:TweenSize(UDim2.new(expBarSize, 0, 0, 20), "Out", "Quad", 0.25)
    else
        script.Parent:TweenSize(UDim2.new(expBarSize, 0, 0, 20), "Out", "Quad", 0.25)
    end
end
 
--ExpText Script (Local Script)
local player = game.Players.LocalPlayer
local exp = player:WaitForChild("leaderstats"):WaitForChild("Exp")
local axp = player:WaitForChild("leaderstats"):WaitForChild("ExpNeeded")
 
while true do
    wait()
    script.Parent.Text = "EXP: " .. exp.Value .. "/" .. axp.Value
end



                                                             GUI 2

GUI 2 is my banking GUI and is a bit more complicated than my experience GUI. It basically displays how much cash a individual has in his/her account, and a count down timer till their next payday. The associated Scripts are below.

PayDay Updater


wait (5)
player = game.Players.LocalPlayer
while true do
	wait ()
	script.Parent.Text = "$"..player.leaderstats.Cash.Value
	
	-- "Time until next payday (+"..player.JobValue.Value.."):"
end


Save Money Module


game.Players.PlayerRemoving:connect(function(p)
if p:findFirstChild("leaderstats") then
p:SaveInstance("SavedStatPNum"..tostring(game.PlaceId),p.leaderstats)
end
end)
game.Players.PlayerAdded:connect(function(p)
for k = 1, 60, 0.03 do
wait()
if p:findFirstChild("leaderstats") and p.DataReady then break end
end
local Loaded = nil
if p:findFirstChild("leaderstats") and pcall(function() Loaded =  p:LoadInstance("SavedStatPNum"..tostring(game.PlaceId)) end) then
for j, v in pairs(Loaded:GetChildren()) do
pcall(function() p.leaderstats[v.Name].Value = v.Value end)
end
end
end)



Payday Script


function onPlayerEntered(newPlayer)
	wait(5)
	local stats = Instance.new("IntValue")
	stats.Name = "leaderstats"
	local cash = Instance.new("IntValue")
	cash.Name = "Cash"
	cash.Value = 5000
	cash.Parent = stats
	stats.Parent = newPlayer
end

game.Players.PlayerAdded:connect(onPlayerEntered)
wait (5)


local time = 600

while true do
	wait(1)
	time = time - 1
	if (time == 0) then
		time = 600
		players = game.Players:GetChildren()
		for i=1, #players do
			if (players[i]:findFirstChild("leaderstats")) then
				
				if (players[i]:IsInGroup(2698900)==true) then -- Determines if they are in the StonyLake Group
					
					players[i].leaderstats.Cash.Value = players[i].leaderstats.Cash.Value + 750
				else
					players[i].leaderstats.Cash.Value = players[i].leaderstats.Cash.Value + 100
				end
			end
		end
	end
	playersa = game.Players:GetChildren()
	for i=1, #playersa do
		playersa[i].PlayerGui.MoneyGui.Frame.Eff.Money.Text = "Time until next payday: " .. tostring(time) -- This will update the GUI
	end
end

I will also include my leaderstat, Just in case its something in there that is wrong.


local level = 1
local exp = 0
local axp = 20
local cash = 0
 
local InStudio = game:GetService("RunService"):IsStudio()
 
if not InStudio then
    level = game:GetService("DataStoreService"):GetDataStore("Levels")
    exp = game:GetService("DataStoreService"):GetDataStore("EXP")
    axp = game:GetService("DataStoreService"):GetDataStore("AXP") -- Amount of exp needed to level up.
    cash = game:GetService("DataStoreService"):GetDataStore("Cash")
end
 
function savedata(dataname, playerid, value)
    if InStudio then return end
    dataname:SetAsync(playerid, value)
end
 
game.Players.PlayerAdded:connect(function(player)
    local leader = Instance.new("Folder")
    leader.Name = "leaderstats"
    leader.Parent = player
    local levelz = Instance.new("IntValue")
    levelz.Name = "Level"
    local xpz = Instance.new("NumberValue")
    xpz.Name = "Exp"
    local xpn = Instance.new("IntValue")
    xpn.Name = "ExpNeeded"
    local cash = Instance.new("IntValue")
    cash.Name = "Cash" 
    if not InStudio then
        xpn.Value = axp:GetAsync(tostring(player.userId)) or 20
        xpz.Value = exp:GetAsync(tostring(player.userId)) or 0
        levelz.Value = level:GetAsync(tostring(player.userId)) or 1
        cash.Value = cash:GetAsync(tostring(player.userId))or 0
    else
        xpn.Value = axp
        xpz.Value = exp
        levelz.Value = level
        cash.Value = cash
    end
   
    levelz.Parent = leader
    xpz.Parent = leader
    xpn.Parent = leader
    cash.Parent = leader
    xpz.Changed:connect(function()
        if player.leaderstats:WaitForChild("Exp").Value >= player.leaderstats:WaitForChild("ExpNeeded").Value then
            levelz.Value = levelz.Value + 1
           
        --[[Here's a cool formula you can try out for higher exp
            n = level
            a = exp required to level up
           
            a = ((n(n+1)/2)*100
        ]]
           
            xpn.Value = math.floor(xpn.Value * 2) --You can change this if you want.
            xpz.Value = 0  
           
            savedata(level, player.userId, levelz.Value)
            savedata(exp, player.userId, xpz.Value)
            savedata(axp, player.userId, xpn.Value)
        else
            savedata(level, player.userId, levelz.Value)
            savedata(exp, player.userId, xpz.Value)
            savedata(axp, player.userId, xpn.Value)
        end
        savedata(level, player.userId, levelz.Value)
        savedata(exp, player.userId, xpz.Value)
        savedata(axp, player.userId, xpn.Value)
    end)
end)
 
game.Players.PlayerRemoving:connect(function(player)
    savedata(level, player.userId, player.leaderstats.Level.Value)
    savedata(exp, player.userId, player.leaderstats.Exp.Value)
    savedata(axp, player.userId, player.leaderstats.ExpNeeded.Value)
    savedata(cash, player.userId, player.leaderstats.Cash.Value)
end)



5 comments

0

you just complicated the problem by showing 6 different scripts. Just look at the output (press F9 or chat /console) and see what the outputs are, and find which script or scripts are going wrong

0

Thank You so much for the insight. I am new to this. there seems to not be any red errors, only yellow ones that say. Infinite yield possible on 'Player.SaxumPierce.leaderstats:WaitForChild("Level') and the same one again but with Exp instead of level.

0

Check your path to "Level" and "Exp".

0

The Main issue I am having is that the entire thing is working in studio, with no issues or complications. Its only when I am in the actual game that it is having this issue. I do not understand or know enough about LUA to troubleshoot this, its beyond my level of comprehension. From what I understand from what I put in my leader, is that there is a folder in each new player and these are in that

0

I assumed they are in the folder, as I put the lines 20 - 30 in my leaderstat making the folder and the individual Values.