Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Billboard GUI not always displayed?

Asked by
Cuvette 246 Moderation Voter
7 years ago

Excuse the mess, but in the script I've made below. It saves the XP/Level etc of the player and loads it all up. But on some servers when people are playing my game, the Billboard Gui doesn't display above their heads with the Level of their player and on other servers the whole thing works fine.

I have noticed it has said Levels is not a valid Int occasionally but I'm sure that's no longer a problem.

local ds = game:GetService("DataStoreService"):GetDataStore("dataone1")
local dso = game:GetService("DataStoreService"):GetOrderedDataStore("levelstore1")

function PlayerAdded(newPlayer)

    local stats = Instance.new("IntValue", newPlayer)
    stats.Name = "leaderstats1"

     local coins = Instance.new("IntValue", stats) 
    coins.Name = "Coins"

    local tokens = Instance.new("IntValue", stats)
    tokens.Name = "Tokens"

    local xp = Instance.new("IntValue", stats)
    xp.Name = "XP"

    local levels = Instance.new("IntValue", stats)
    levels.Name = "Levels"

    local coinKey = ds:GetAsync("Key" .. newPlayer.Name) 
    if coinKey then
        coins.Value = coinKey
    else
        coins.Value = 0
    end

    local tokensKey = ds:GetAsync("Key1" .. newPlayer.Name)
    if  tokensKey then
        tokens.Value = tokensKey
    else
        tokens.Value = 0
    end
    local xpKey = ds:GetAsync("Key2" .. newPlayer.Name)
    if xpKey then
        xp.Value =xpKey
    else
        xp.Value = 0
    end
    local levelsKey = dso:GetAsync("" .. newPlayer.Name)
    if levelsKey then
        levels.Value = dso:GetAsync("" .. newPlayer.Name)    
    else
        levels.Value = 1
    end

        coins.Changed:connect(function(save)
            ds:SetAsync("Key" .. newPlayer.Name, save)
        end)
        tokens.Changed:connect(function(save)
            ds:SetAsync("Key1" .. newPlayer.Name, save)
        end)

    local xpDeb = false
        xp.Changed:connect(function()
        if xpDeb then return end
        xpDeb = true
        while xp.Value >= 100 do
            xp.Value = xp.Value - 100
            levels.Value = levels.Value + 1
        end
            ds:SetAsync("Key2" .. newPlayer.Name, xp.Value)
        dso:SetAsync("" .. newPlayer.Name, levels.Value)
        xpDeb = false
        end)
end

function CharacterAdded(newPlayer)
    wait(6)
    newPlayer.leaderstats1:WaitForChild("Levels")
    local gui=Instance.new("BillboardGui")
    gui.Parent=newPlayer.Character.Head
    gui.Adornee=newPlayer.Character.Head
    gui.Size=UDim2.new(3,0,2,0)
    gui.StudsOffset=Vector3.new(0,2,0)
    local text=Instance.new("TextLabel")    
    text.TextColor3 = Color3.new(255, 255, 255)
    text.Text = "Level " .. newPlayer.leaderstats1.Levels.Value
    text.Size=UDim2.new(1.25,0,0.5,0)
    text.Position=UDim2.new(-0.125,0,-0.25,0)
    text.BackgroundTransparency = 1
    text.Parent=gui
    text.FontSize = ("Size36")
    text.Font = ("SourceSansBold")

    text.TextStrokeColor3 = Color3.new(0.50, 0.50, 0.50)
    text.TextStrokeTransparency = 0
    w = game.Lighting.WepsGroup:GetChildren() 
    for i = 1,#w do
        w[i]:Clone().Parent = newPlayer.Backpack
    end
end


function onPlayerEntered(newPlayer) 
    newPlayer.Changed:connect(function (property) 
        if (property == "Character") then 
            CharacterAdded(newPlayer) 
        end 
    end) 
end 
game.Players.PlayerAdded:connect(onPlayerEntered) 
game.Players.PlayerAdded:connect(PlayerAdded)

0
Get your code down to about 20 or fewer relevent lines of code first. We don't want to see all the gui manipulation if it isn't showing up in the first place. GoldenPhysics 474 — 7y
0
That's the problem, it is showing on some servers and on others it's not at all. And this goes for everyone in the server. I've got just over 100 people on right now and half of the servers are not showing the GUI. Cuvette 246 — 7y
0
Did you check the Output for anything? Or the f9 developer console in your game?... StoIid 364 — 7y
0
Yeah i'm getting nothing, but rarely I get a 'Levels is not a valid Int' error and that's when it doesn't display. But i'm not quite sure why this is happening sometimes and not others. Cuvette 246 — 7y

Answer this question