Leaderstats live updating is not working

Good evening everyone

I have a leaderstats which is working perfectly. I am trying to transfer the data to a GUI Leaderboard. It is a “King of the hill” kind of game. The Hillpoints are updating but I am not sure how to get that live update working in the GUI. It just stays “0”.

This is the leaderstats script:

local function addRowToPlayers(player)

local frm = ReplicatedStorage:WaitForChild("PlayerRow")
for _, p in pairs(game.Players:GetChildren()) do
	local pGui = p:WaitForChild("PlayerGui")
	local sGui = pGui:WaitForChild("LeaderBoardGUI")
	local cloneFrm = frm:Clone()
	cloneFrm.Name = player.Name
	cloneFrm.PlayerLBL.Text =player.Name
	cloneFrm.HillLBL.Text = 0
	cloneFrm.Parent = sGui:WaitForChild("LeaderFrame")
end
local cloneFrm = frm:Clone()
cloneFrm.Name = player.Name
cloneFrm.PlayerLBL.Text =player.Name
cloneFrm.HillLBL.Text = 0
cloneFrm.Parent = screenGUI:WaitForChild("LeaderFrame")

end

This is the code which updates the Hillpoints:

for _ , v in pairs (game.Players:GetPlayers()) do 
	local HillPoints = v:FindFirstChild("leaderstats").HillPoints
	if v.InHill.Value == true then
		HillPoints.Value = HillPoints.Value + 1
	end
	v.InHill.Value = false
end

How do I send that Hillpoints value to the GUI? I tried simply referencing the LocalPlayer.leaderstats.Hillpoints.value but it just tells me that I am trying to connect a nill value. What am I doing wrong?

I can’t see the leaderstats script

This is it

game.Players.PlayerAdded:Connect(function(Player)
local leaderstats = Instance.new(“Folder”)
leaderstats.Name = “leaderstats”
leaderstats.Parent = Player

local HillPoints = Instance.new("IntValue")
HillPoints.Name = "HillPoints"
HillPoints.Value = 0
HillPoints.Parent = leaderstats

local InHill = Instance.new("BoolValue")
InHill.Name = "InHill"
InHill.Value = false
InHill.Parent = Player

game.Players.PlayerAdded:Connect(function(player)

How frequently is that for loop ran? If it’s just the once then there’s your issue.

adding on, a while true do would be suitable

also, you could do some sort of condition for the loop to run

I prefer to steer away from indefinite loop constructs and instead gravitate towards code that follows an event driven paradigm.

It is run continuously while the player is standing on the hill. It stops as soon as he gets off. It is working in the normal leaderstats, the problem seems to be that it is not picking up that value in the Leaderboard GUI

Yeah because PlayerGui is used in local plrs. Not in game.Players:GetChildren()

At the risk of sounding clueless (which I am at this stage…), so should I move PlayerGui to Player?

You can only access PlayerGui with local plr in a local script.

I dont know why you are looping like that.

1 Like

It is the result of mixing three different tutorials, and at some point getting lost and messing it up completely. I guess I will have to rethink the whole process.