BillboardGui Serverside Help

Hi everyone, I’m having struggles with something. I’m trying to show the players on server but its not budging, it gets the players level when you first load in but it wont update when you level up, i did try the IntValue.Changed, still not budging.

local repstorage = game.ReplicatedStorage.BillboardGui.StatShower

game.Players.PlayerAdded:Connect(function(player)
	local levels = player:WaitForChild("leaderstats").Levels
	repstorage.Text = "Level: "..levels.Value
	
end)

end)

This script makes it where you spawn with a gui on your head

local repstorage = game.ReplicatedStorage.BillboardGui

game.Players.PlayerAdded:Connect(function(player)
	
	player.CharacterAdded:Connect(function(character)
		
		local cloneUI = repstorage:Clone()
		
		cloneUI.Parent = character.Head
		
	end)
end)

Image to show what im talking about

Is the first code you put from a local script?

You should instead make use of the Changed event if you want to detect a change of value.

Just do:

local levels = player:WaitForChild("leaderstats").Levels
levels.Changed:Connect(function(newVal)
   repstorage.Text = "Level: " .. newVal
end)

So where you see the level counter on the bottem left corner, thats local, im trying to make the billboard gui serverside, so everyone can see your level, ive been trying to solve this issue for a couple of days now.

It should look like this:

local repstorage = game.ReplicatedStorage.BillboardGui

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local cloneUI = repstorage:Clone()
		cloneUI.StatShower.Text = "Level: "..player.leaderstats.Levels.Value
		cloneUI.Parent = character.Head
	end)
end)

You can completely remove the other script.

2 Likes

Alright i did as you said, i only used this script you gave nothing else, it cloned the gui and stuff, it shows the level you spawned with, but when i level up it doesnt change, it stays at the same level you started with

before level up when spawning in

after level up

its not keeping track

Add from this script you didn’t insert changed event for level so it should look like this

local repstorage = game.ReplicatedStorage.BillboardGui

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local cloneUI = repstorage:Clone()
		cloneUI.StatShower.Text = "Level: "..player.leaderstats.Levels.Value
		cloneUI.Parent = character.Head

player.leaderstats.Levels.Changed:Connect(function(newLV)
cloneUI.StatShower.Text = "Level: "..newLV
end)
	end)
end)

Yes, the problem is exactly what @RandomPlayerOne1 mentioned. Although, I would personally go a different route with the solution to that as to save performance (even if only a sliver)

local repstorage = game.ReplicatedStorage.BillboardGui

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local cloneUI = repstorage:Clone()
		cloneUI.StatShower.Text = "Level: "..player.leaderstats.Levels.Value
		cloneUI.Parent = character.Head
	end)

	player:WaitForChild("leadersats"):WaitForChild("Levels"):GetPropertyChangedSignal("Value"):Connect(function()
		if player.Character and player.Character:FindFirstChild("BillboardGui") then
			player.Character.BillboardGui.StatShower.Text = "Level: "..player.leaderstats.Levels.Value
		end
	end)
end)

Quickly made a datastore with “Swings”, “XP”, “Levels”
I tested and it worked, please let me know if it works for you.
This is the only script you need.

If this doesn’t work make sure you’re changing your level in the server, not the client.

local dataStoreService = game:GetService("DataStoreService")

local dataStore = dataStoreService:GetDataStore("Test")

local function levelsGui(player, levels)
    task.wait(0.1)
    local character = player.Character
    local CloneUI = game.ReplicatedStorage.BillboardGui:Clone() -- Path to the "CloneUI"
    CloneUI.Parent = character:FindFirstChild("Head")
    CloneUI.TextLabel.Text = levels.Value -- whatever the textLabel is inside of "CloneUI"
    levels.Changed:Connect(function()
        local newVal = "Level: "..levels.Value
        CloneUI.TextLabel.Text = "Level: "..newVal -- whatever the textLabel is inside of "CloneUI"
    end)
end


game.Players.PlayerAdded:Connect(function(player)
    local leaderstats = Instance.new("Folder", player)
    leaderstats.Name = "leaderstats"
    local swings = Instance.new("NumberValue", leaderstats)
    swings.Name = "Swings"
    swings.Value = 0
    local experience = Instance.new("NumberValue", leaderstats)
    experience.Name = "XP"
    experience.Value = 0
    local levels = Instance.new("NumberValue", leaderstats)
    levels.Name = "Levels"
    levels.Value = 0    
    
    local dataSwings
    local dataXP
    local dataLevels
    local success, failure = pcall(function()
        local key1 = player.UserId.."Swings"
        local key2 = player.UserId.."XP"
        local key3 = player.UserId.."Levels"
        dataSwings = dataStore:GetAsync(key1)
        dataXP = dataStore:GetAsync(key2)
        dataLevels = dataStore:GetAsync(key3)
    end)
    if success then
        if dataSwings and dataXP and dataLevels ~= nil then
            swings.Value = dataSwings
            experience.Value = dataXP
            levels.Value = dataLevels
            print("Data loaded successfully: ["..player.Name.."; "..player.UserId.."]")
            player.CharacterAdded:Connect(function()
                levelsGui(player, levels)
            end)
        else
            print("Data was nil: ["..player.Name.."; "..player.UserId.."]")
            player.CharacterAdded:Connect(function()
                levelsGui(player, levels)
            end)
        end
    else
        print("Data was not loaded successfully: ["..player.Name.."; "..player.UserId.."]")
        warn(failure)
    end
end)

game.Players.PlayerRemoving:Connect(function(player)
    local success, failure = pcall(function()
        local key1 = player.UserId.."Swings"
        local key2 = player.UserId.."XP"
        local key3 = player.UserId.."Levels"
        dataStore:SetAsync(key1, player.leaderstats.Swings.Value)
        dataStore:SetAsync(key2, player.leaderstats.XP.Value)
        dataStore:SetAsync(key3, player.leaderstats.Levels.Value)
    end)
    if success then
        print("Data saved successfully: ["..player.Name.."; "..player.UserId.."]")
    else
        print("Data not saved: ["..player.Name.."; "..player.UserId.."]")
        warn(failure)
    end
end)

So the data save works, so does the leaderstats, but the billboard gui doesnt seem to be showing, I even fixed the text lable path, i even tested it on a clear baseplate, i even put it in the server. But if theres anything im doing wrong just tell me

Where is your billboard GUI located and is it enabled? Same with your text label is it enabled?

So the billboard gui is located in replicated storage, and yes billboard gui is enable same with the text lable

Can you show me the edited script?

absolutely

local dataStoreService = game:GetService("DataStoreService")

local dataStore = dataStoreService:GetDataStore("Test")

local function levelsGui(player, levels)
	task.wait(0.1)
	local character = player.Character
	local CloneUI = game.ReplicatedStorage.BillboardGui:Clone() -- Path to the "CloneUI"
	CloneUI.Parent = character:FindFirstChild("Head")
	CloneUI.StatShower.Text = levels.Value -- whatever the textLabel is inside of "CloneUI"
	levels.Changed:Connect(function()
		local newVal = "Level: "..levels.Value
		CloneUI.StatShower.Text = "Level: "..newVal -- whatever the textLabel is inside of "CloneUI"
	end)
end


game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder", player)
	leaderstats.Name = "leaderstats"
	local swings = Instance.new("NumberValue", leaderstats)
	swings.Name = "Swings"
	swings.Value = 0
	local experience = Instance.new("NumberValue", leaderstats)
	experience.Name = "XP"
	experience.Value = 0
	local levels = Instance.new("NumberValue", leaderstats)
	levels.Name = "Levels"
	levels.Value = 0    

	local dataSwings
	local dataXP
	local dataLevels
	local success, failure = pcall(function()
		local key1 = player.UserId.."Swings"
		local key2 = player.UserId.."XP"
		local key3 = player.UserId.."Levels"
		dataSwings = dataStore:GetAsync(key1)
		dataXP = dataStore:GetAsync(key2)
		dataLevels = dataStore:GetAsync(key3)
	end)
	if success then
		if dataSwings and dataXP and dataLevels ~= nil then
			swings.Value = dataSwings
			experience.Value = dataXP
			levels.Value = dataLevels
			print("Data loaded successfully: ["..player.Name.."; "..player.UserId.."]")
			player.CharacterAdded:Connect(function()
				levelsGui(player, levels)
			end)
		else
			print("Data was nil: ["..player.Name.."; "..player.UserId.."]")
			player.CharacterAdded:Connect(function()
				levelsGui(player, levels)
			end)
		end
	else
		print("Data was not loaded successfully: ["..player.Name.."; "..player.UserId.."]")
		warn(failure)
	end

the places u told me to edit i edited

1 Like

I must’ve made a mistake on my behalf, I will edit the script and fix it, sorry about that.

as you can see, this is my level when I spawn in.


I changed the level in the player.leaderstats and now…

Alright, I fixed the script I have made, here it is.

local dataStoreService = game:GetService("DataStoreService")

local dataStore = dataStoreService:GetDataStore("Test")

local function levelsGui(player, levels)
    player.CharacterAdded:Connect(function(character)
        local CloneUI = game.ReplicatedStorage.BillboardGui:Clone() -- Path to the "CloneUI"
        CloneUI.Parent = character:FindFirstChild("Head")
        CloneUI.TextLabel.Text = "Level: "..levels.Value -- whatever the textLabel is inside of "CloneUI"
        levels.Changed:Connect(function()
            local newVal = "Level: "..levels.Value
            CloneUI.TextLabel.Text = newVal -- whatever the textLabel is inside of "CloneUI"
        end)
    end)
    if player.Character then
        local character = player.Character
        local CloneUI = game.ReplicatedStorage.BillboardGui:Clone() -- Path to the "CloneUI"
        CloneUI.Parent = character:FindFirstChild("Head")
        CloneUI.TextLabel.Text = "Level: "..levels.Value -- whatever the textLabel is inside of "CloneUI"
        levels.Changed:Connect(function()
            local newVal = "Level: "..levels.Value
            CloneUI.TextLabel.Text = newVal -- whatever the textLabel is inside of "CloneUI"
        end)
    end
end


game.Players.PlayerAdded:Connect(function(player)
    local leaderstats = Instance.new("Folder", player)
    leaderstats.Name = "leaderstats"
    local swings = Instance.new("NumberValue", leaderstats)
    swings.Name = "Swings"
    swings.Value = 0
    local experience = Instance.new("NumberValue", leaderstats)
    experience.Name = "XP"
    experience.Value = 0
    local levels = Instance.new("NumberValue", leaderstats)
    levels.Name = "Levels"
    levels.Value = 0    

    local dataSwings
    local dataXP
    local dataLevels
    local success, failure = pcall(function()
        local key1 = player.UserId.."Swings"
        local key2 = player.UserId.."XP"
        local key3 = player.UserId.."Levels"
        dataSwings = dataStore:GetAsync(key1)
        dataXP = dataStore:GetAsync(key2)
        dataLevels = dataStore:GetAsync(key3)
    end)
    if success then
        if dataSwings and dataXP and dataLevels ~= nil then
            swings.Value = dataSwings
            experience.Value = dataXP
            levels.Value = dataLevels
            print("Data loaded successfully: ["..player.Name.."; "..player.UserId.."]")
            print("1")
            levelsGui(player, levels)
        else
            print("Data was nil: ["..player.Name.."; "..player.UserId.."]")
            levelsGui(player, levels)
        end
    else
        print("Data was not loaded successfully: ["..player.Name.."; "..player.UserId.."]")
        warn(failure)
    end
end)

game.Players.PlayerRemoving:Connect(function(player)
    local success, failure = pcall(function()
        local key1 = player.UserId.."Swings"
        local key2 = player.UserId.."XP"
        local key3 = player.UserId.."Levels"
        dataStore:SetAsync(key1, player.leaderstats.Swings.Value)
        dataStore:SetAsync(key2, player.leaderstats.XP.Value)
        dataStore:SetAsync(key3, player.leaderstats.Levels.Value)
    end)
    if success then
        print("Data saved successfully: ["..player.Name.."; "..player.UserId.."]")
    else
        print("Data not saved: ["..player.Name.."; "..player.UserId.."]")
        warn(failure)
    end
end)

Question do i have to upload the game for the level thing too work

You need the game published for the DataStoreService, with “Allow HTTP Requests” and “Enable Studio Access to API Services” enabled. You can find these two options in the game settings.

1 Like

hmm alright, again i see that its working for you, but the gui thing is not showing up, the weird part is that there is no errors