Character Values not showing

I’m making a leaderboard and everything is working except displaying the player’s name and stats. This is my script:

local scoreboard = script.Parent
local main = scoreboard.BG
local holder = main.StatsHold
local temp = holder.Template

local UIS = game:GetService("UserInputService")

local function clear()
	for i,v in pairs(holder:GetChildren()) do
		if v:IsA("Frame") then
			v:Destroy()
		end
	end
end

local function generate()

	for i,player in pairs(game.Players:GetPlayers()) do

		local PS = player:FindFirstChild("PlayerStats")
		local kills = PS.kills
		local deaths = PS.deaths

		local c = temp:Clone()
		c.user.Text = player.Name
		c.kills.Text = kills.Value
		c.deaths.Text = deaths.Value
		c.Parent = holder
	end

end

Can anyone tell me why the values and names aren’t displaying?

I’m afraid nothing wrong with the script :sweat_smile:

oh god… well then that’s a problem…

Just to make sure, this is in a local script, right?
How are these functions being called? It may help to know whether they are being called at all.
On first glance, I don’t see anything explicitly wrong with the code. Is there code setting the position of the GUI elements?

could you show me full script, thanks ?

That was the full script (Client sided). The other is just the leaderstats and that works perfectly fine.

Sorry if I misinterpreted this.

Yes it is in a local script.
There is a server sided script that gather the values of the kills and deaths and the ui texts get updated to that as you can see in

local function generate()

	for i,player in pairs(game.Players:GetPlayers()) do

		local PS = player:FindFirstChild("PlayerStats")
		local kills = PS.kills
		local deaths = PS.deaths

		local c = temp:Clone()
		c.user.Text = player.Name
		c.kills.Text = kills.Value
		c.deaths.Text = deaths.Value
		c.Parent = holder
	end

end

If that’s the full script, then it seems that it does not call the generate or clear functions. This is why it doesn’t display the leaderboard stats. You’d need to do some work on the server side script for it to communicate to the players whenever the stats change.

This is the server script:

game.Players.PlayerAdded:Connect(function(plr)
	
	local plrStats = Instance.new("Folder", plr)
	plrStats.Name = "PlayerStats"
	
	local Kills = Instance.new("IntValue", plr)
	Kills.Name = "kills"
	
	local deaths = Instance.new("IntValue", plr)
	deaths.Name = "deaths"
	
	local char = plr.Character or plr.CharacterAdded:Wait()
	local humanoid  = char:FindFirstChild("Humanoid")
	
	humanoid.Died:Connect(function()
		deaths.Value += 1
	end)
end)

What can I add here?

Congratulations on joining the kool kids by using +=. :stuck_out_tongue:

More seriously, the simplest way of handling this without having to deal with a massive number of connections would be to use a RemoteEvent.

-- Server Script
local remEvt = Instance.new("RemoteEvent")
remEvt.Name = "LeaderboardEvent"
remEvt.Parent = game.ReplicatedStorage

game.Players.PlayerAdded:Connect(function(plr)
	local plrStats = Instance.new("Folder", plr)
	plrStats.Name = "PlayerStats"

	local Kills = Instance.new("IntValue", plr)
	Kills.Name = "kills"

	local deaths = Instance.new("IntValue", plr)
	deaths.Name = "deaths"

	local char = plr.Character or plr.CharacterAdded:Wait()
	local humanoid  = char:FindFirstChild("Humanoid")

	humanoid.Died:Connect(function()
		deaths.Value += 1
		remEvt:FireAllClients()
	end)
end)
-- Local Script 
local scoreboard = script.Parent
local main = scoreboard.BG
local holder = main.StatsHold
local temp = holder.Template
local remEvt = game.ReplicatedStorage:WaitForChild("LeaderboardEvent")

local generate = function()
	for i,v in pairs(holder:GetChildren()) do
		if v:IsA("Frame") then
			v:Destroy()
		end
	end
	
	for i,player in pairs(game.Players:GetPlayers()) do
		local PS = player:FindFirstChild("PlayerStats")
		local kills = PS.kills
		local deaths = PS.deaths

		local c = temp:Clone()
		c.user.Text = player.Name
		c.kills.Text = kills.Value
		c.deaths.Text = deaths.Value
		c.Parent = holder
	end
end

remEvt.OnClientEvent:Connect(generate)

I refactored your code slightly; since your current set up has you clear the leaderboard each and every time you want to update it, it makes more sense to include the clear function at the start of the generate function.
This script isn’t perfect, though. I would suggest reworking it so that it simply updates the text of the leaderboard rather than totally refreshing it.

I hope this helps!

There is an error where “kills” is not a valid member of Folder “Players.s0808.PlayerStats”

so, im back. i just eat a while ago :sweat_smile:

I believe we don’t need remote event because we can do on client side only. Anything changes on server get replicated on client also such as kill or death stats

scoreBoard.rbxm (9.2 KB)

I only test on studio.

you are not calling or Invokeing the functions

For some reason, on your model it seems to work but when I try to implement the script to mine it doesnt lol