Problem with Billboard gui

Hello,
I would like to display a billboard gui above the heads of all players with “the number of stars received” via the leaderstats of my game.

I added this script in ServerScriptService:

local Players = game:GetService('Players')
local BillboardGui = game.ServerStorage.BillboardGui

Players.PlayerAdded:Connect(function(Player)
	local Stars = Player.leaderstats['Stars']

	Player.CharacterAdded:Connect(function(Character)
		local BillboardClone = BillboardGui:Clone()
		BillboardClone.Parent = Character:WaitForChild("Head")
		BillboardClone.TextLabel.Text = Stars.Value

		Stars:GetPropertyChangedSignal('Value'):Connect(function()
			BillboardClone.TextLabel.Text = Stars.Value
		end)
	end)
end)

But I have this error that comes out: “leaderstats is not a valid member of Player “Players.Aikious” - Server - Script:5”
I am a newbie, if anyone can help me please :smiling_face:

Wait for it load also did u make the leaderstats too

local Players = game:GetService('Players')
local BillboardGui = game.ServerStorage.BillboardGui

Players.PlayerAdded:Connect(function(Player)
	local Stars = Player:WaitForChild("leaderstats")['Stars']

	Player.CharacterAdded:Connect(function(Character)
		local BillboardClone = BillboardGui:Clone()
		BillboardClone.Parent = Character:WaitForChild("Head")
		BillboardClone.TextLabel.Text = Stars.Value

		Stars:GetPropertyChangedSignal('Value'):Connect(function()
			BillboardClone.TextLabel.Text = Stars.Value
		end)
	end)
end)

yes, also in ServerScriptService:

--\\ SERVICES //--

local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local RepStorage = game:GetService("ReplicatedStorage")
local DataStoreService = game:GetService("DataStoreService")
local MarketplaceService = game:GetService("MarketplaceService")
local ServerScriptService = game:GetService("ServerScriptService")

local RemovePrompt = RepStorage.RemovePrompt

local purchasedatastore = DataStoreService:GetDataStore("PurchaseDatastore")
local DataStore = DataStoreService:GetOrderedDataStore("TopStars")

local ManageData = require(ServerScriptService.DataManager)

local function LoadData (Plr)
	local DataValue = Plr.leaderstats.Stars
	local Text = "Stars"

	local Key = Plr.UserId
	local Retry = 0
	local Success
	local GetSaved

	repeat
		Retry = Retry + 1
		Success,GetSaved = pcall(function()	
			return DataStore:GetAsync(Key)		
		end)
		if not Success then
			wait(1)
		end
	until Retry == 3 or Success

	if Success then
		if GetSaved then
			print(Plr.Name.." has "..Text.." = "..GetSaved)
			DataValue.Value = GetSaved
		else
			print(Plr.Name.." is new player! "..Text.." = 0")
			DataValue.Value = 0
		end
	else
		print(Text.." couldn't load for "..Plr.Name)
	end
end

local function AddPurchases (Plr)
	local purchasesvalue = Instance.new("IntValue")
	purchasesvalue.Name = "Purchases"
	local success = pcall(function()
		local purchasedata = purchasedatastore:GetAsync(Plr.UserId)

		if purchasedata then
			purchasesvalue.Value = purchasedata
		else
			purchasesvalue.Value = 0
		end
	end)

	if not success then
		purchasesvalue.Value = 0
	end
	purchasesvalue.Parent = Plr.leaderstats
end

Players.PlayerAdded:connect(function(Plr)
	
	local JuryValue = Instance.new("BoolValue")
	JuryValue.Name = "Jury"
	JuryValue.Value = false	
	JuryValue.Parent = Plr  

	local leaderstats = Instance.new("Model")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = Plr   
	
	local Stars = Instance.new("IntValue")
	Stars.Name = "Stars"
	Stars.Value = 0
	Stars.Parent = leaderstats
	
	RemovePrompt:FireClient(Plr)
	
	AddPurchases (Plr)
	LoadData(Plr)
end)

game:BindToClose(function()
	for _, client in ipairs(Players:GetPlayers()) do
		print("saving for player")
		coroutine.wrap(ManageData.DataSave)(client)
	end
end)

Players.PlayerRemoving:Connect(ManageData.UpdateData)

I still get an error: TextLabel is not a valid member of BillboardGui “BillboardGui” - Server - Script:13

Is TextLabel inside the billboardGui?

yes, he is inside, and BillboardGui is inside ServerStorage

I’m not sure this is what’s causing this error, but why did you make a different script for this, even though below you have another script that runs the same Players.PlayerAdded event?
Have you thought that this script is running before the other script is?

I don’t know, this script was created by a pro scripter, and I just wanted to display the leaderstats of the stars above the heads of the players, but if you think that I can add this function in the same script tell me how ?

Players.PlayerAdded:Connect(function(Plr)
	local JuryValue = Instance.new("BoolValue")
	JuryValue.Name = "Jury"
	JuryValue.Value = false	
	JuryValue.Parent = Plr  

	local leaderstats = Instance.new("Model")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = Plr   
	
	local Stars = Instance.new("IntValue")
	Stars.Name = "Stars"
	Stars.Value = 0
	Stars.Parent = leaderstats
	
	RemovePrompt:FireClient(Plr)
	
	AddPurchases (Plr)
	LoadData(Plr)

	Plr.CharacterAdded:Connect(function(Character)
		local BillboardClone = BillboardGui:Clone()
		BillboardClone.Parent = Character:WaitForChild("Head")
		BillboardClone.TextLabel.Text = Stars.Value

		Stars:GetPropertyChangedSignal('Value'):Connect(function()
			BillboardClone.TextLabel.Text = Stars.Value
		end)
	end)
end)

it doesn’t change anything, no billboardGui is displayed

Oh I found it! just had to modify this line BillboardClone.Parent = Character:WaitForChild("Head") for BillboardClone.Parent = game.Workspace:WaitForChild(Plr.Name).Head

Glad to hear you solved the problem!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.