Custom Player List stats not updating the correct player

Hello,

This is my first time posting here, apologies if I’m doing this wrong, or have this formatted incorrectly. :slight_smile:

I’ve created a custom player list that will display a user’s: Avatar Image, Name, RoundKills, KillStreak.

Unfortunately, while the RoundKills and KillStreak, which are leaderstats Values, do update in real time, the stats are not updating for the correct player. For example: Player 1 scored a kill, yet on Player1’s screen it shows Player3 as having done this, while on Player2’s screen, it shows that Player1 did. What I’d like to do is make it to where the RoundKills/Killstreak update for the correct player, and still do so in real time for everyone else.

Here’s an image showing this:

Image1

My custom player list is created by this local script code inside a ScreenGui, and has the lines where the RoundKills & Killstreak display,

CODE:

game.StarterGui:SetCoreGuiEnabled("PlayerList", false)
local plr = game.Players.LocalPlayer
local kills = plr.leaderstats.Roundkills.Value
local killstreak = plr.leaderstats.Killstreak.Value
local Avatarurl = "http://www.roblox.com/Thumbs/Avatar.ashx?x=500&y=500&Format=Png&username="
local gui = script.Parent

while wait(1) do
	
    for _,plr in pairs (game.Players:GetChildren()) do
        if script.Parent.Holder:FindFirstChild(plr.Name) then

        else
            local kills2 = plr.leaderstats.Roundkills.Value
            local killstreak2 = plr.leaderstats.Killstreak.Value
            I = Instance.new("Frame")
            I.Name = plr.Name
            I.Parent = script.Parent.Holder
            I.Style = "DropShadow"
-- NAME        
            T = Instance.new("TextLabel")
			T.Name = "Username"
            T.BackgroundTransparency = 1
            T.Text = plr.Name
            T.Parent = I
            T.Size = UDim2.new(0, 165, 0, 35)
            T.Position = UDim2.new(0, 10, 0, 0)
            if plr.Name == game.Players.LocalPlayer.Name then
                T.TextColor3 = Color3.fromRGB(0, 200, 255)
                else
            T.TextColor3 = Color3.new(1, 1, 1)
            end
            T.TextStrokeColor3 = Color3.new(0, 0, 0)
            T.TextStrokeTransparency = 0.5
            T.TextXAlignment = "Left"
            T.Font = "SourceSansBold"
            T.TextSize = 20
-- ROUND KILLS           
            K = Instance.new("TextLabel")
			K.Name = "RoundKills"
            K.BackgroundTransparency = 1
			K.Text = kills2     
            K.Parent = I
            K.Size = UDim2.new(0, 20, 0, 35)
            K.Position = UDim2.new(0, 155, 0, 0)
            K.TextColor3 = Color3.new(1, 1, 1)
                K.TextStrokeColor3 =  Color3.new(0, 0, 0)
                K.TextStrokeTransparency = 0.5
                K.TextXAlignment = "Right"
                K.Font = "SourceSansBold"
                K.TextSize = 20


-- KILL STREAK
            KS = Instance.new("TextLabel")
			KS.Name = "KillStreak"
            KS.BackgroundTransparency = 1
            KS.Text = killstreak2
            KS.Parent = I
            KS.Size = UDim2.new(0, 20, 0, 35)
            KS.Position = UDim2.new(0, 167, 0, 0)
            KS.TextColor3 = Color3.new(255,0,0)
                KS.TextStrokeColor3 =  Color3.new(0, 0, 0)
                KS.TextStrokeTransparency = 0.5
                KS.TextXAlignment = "Right"
                KS.Font = "SourceSansBold"
                KS.TextSize = 20

-- AVATAR IMAGE
            P = Instance.new("ImageLabel")
			P.ScaleType = "Slice"
			P.Name = "AvatarImage"
            P.BackgroundTransparency = 1
            P.Image = Avatarurl..plr.Name
            P.Parent = I
            P.Size = UDim2.new(.25,0,1.25,0)
            P.Position = UDim2.new(-0.25, 0, 0, 0)


game:GetService("ReplicatedStorage"):WaitForChild("KillUpdate").OnClientEvent:Connect(function(value)
    K.Text = value
end)

game:GetService("ReplicatedStorage"):WaitForChild("KillStreakUpdate").OnClientEvent:Connect(function(value)
    KS.Text = value
end)


end
end
end

I have this bit of code in my Leaderstats script in ServerScriptStorage:

Roundkills.Changed:Connect(function()
    game:GetService("ReplicatedStorage"):WaitForChild("KillUpdate"):FireClient(Player, Roundkills.Value)
	end)
	print("RoundKills check")
	
	Killstreak.Changed:Connect(function()
    game:GetService("ReplicatedStorage"):WaitForChild("KillStreakUpdate"):FireClient(Player, Killstreak.Value)
	end)
	print("Killstreak check")

And finally in my DeathScript I have this bit of code that updates the RoundKills and KillStreak stats in the first place after a player is killed, just in case something here need to be done:

leaderstats.Roundkills.Value = leaderstats.Roundkills.Value + 1 
leaderstats.Killstreak.Value = leaderstats.Killstreak.Value + 1 

I’ve tried messing with this several ways, and have yet to get it correct. I’ll be the first to admit that my knowledge of remote events is shakey and I wonder if that’s where the problem is?

Thank you!

If you try this with the roblox default leaderboard - does it work?

Yes, default leaderboard works fine.:slight_smile: no problem with my leaderstats.

LocalScript:

game.StarterGui:SetCoreGuiEnabled("PlayerList", false)
local plr = game.Players.LocalPlayer

local gui = script.Parent
local PlayerListFrame = gui:WaitForChild('PlayerListFrame')

local PlayerListUpdate = game.ReplicatedStorage:WaitForChild('PlayerListUpdate')



function UpdatePlayerList()
	for i,v in ipairs(game.Players:GetPlayers()) do
		if not PlayerListFrame:findFirstChild(v.Name) then
			local kills2 = v.leaderstats.RoundKills.Value
           	local killstreak2 = v.leaderstats.Killstreak.Value
          	local I = Instance.new("Frame")
            I.Name = v.Name
            I.Parent = PlayerListFrame
            I.Style = "DropShadow"
-- NAME        
            local T = Instance.new("TextLabel")
			T.Name = "Username"
            T.BackgroundTransparency = 1
            T.Text = v.Name
            T.Parent = I
            T.Size = UDim2.new(0, 165, 0, 35)
            T.Position = UDim2.new(0, 10, 0, 0)
            if v.Name == plr.Name then
                T.TextColor3 = Color3.fromRGB(0, 200, 255)
            else
           		T.TextColor3 = Color3.new(1, 1, 1)
            end
            T.TextStrokeColor3 = Color3.new(0, 0, 0)
            T.TextStrokeTransparency = 0.5
            T.TextXAlignment = "Left"
            T.Font = "SourceSansBold"
            T.TextSize = 20
-- ROUND KILLS           
            local K = Instance.new("TextLabel")
			K.Name = "RoundKills"
            K.BackgroundTransparency = 1
			K.Text = kills2     
            K.Parent = I
            K.Size = UDim2.new(0, 20, 0, 35)
            K.Position = UDim2.new(0, 155, 0, 0)
            K.TextColor3 = Color3.new(1, 1, 1)
                K.TextStrokeColor3 =  Color3.new(0, 0, 0)
                K.TextStrokeTransparency = 0.5
                K.TextXAlignment = "Right"
                K.Font = "SourceSansBold"
                K.TextSize = 20


-- KILL STREAK
          	local KS = Instance.new("TextLabel")
			KS.Name = "KillStreak"
            KS.BackgroundTransparency = 1
            KS.Text = killstreak2
            KS.Parent = I
            KS.Size = UDim2.new(0, 20, 0, 35)
            KS.Position = UDim2.new(0, 167, 0, 0)
            KS.TextColor3 = Color3.new(255,0,0)
                KS.TextStrokeColor3 =  Color3.new(0, 0, 0)
                KS.TextStrokeTransparency = 0.5
                KS.TextXAlignment = "Right"
                KS.Font = "SourceSansBold"
                KS.TextSize = 20

-- AVATAR IMAGE
            P = Instance.new("ImageLabel")
			P.ScaleType = Enum.ScaleType.Slice
			P.Name = "AvatarImage"
            P.BackgroundTransparency = 1
            P.Image = "http://www.roblox.com/Thumbs/Avatar.ashx?x=500&y=500&Format=Png&username="..v.Name
            P.Parent = I
            P.Size = UDim2.new(.25,0,1.25,0)
            P.Position = UDim2.new(-0.25, 0, 0, 0)
		else
			local kills2 = v.leaderstats.RoundKills.Value
           	local killstreak2 = v.leaderstats.Killstreak.Value
			local PlayerFrame = PlayerListFrame:findFirstChild(v.Name)
			PlayerFrame:WaitForChild('KillStreak').Text = killstreak2
			PlayerFrame:WaitForChild('RoundKills').Text = kills2
		end	
	end
end

game.Players.PlayerAdded:connect(function(plr)
	UpdatePlayerList()
end)

UpdatePlayerList()

PlayerListUpdate.OnClientEvent:connect(function(args)
	if args['Action'] == 'Update' then
		UpdatePlayerList()
	end
end)

Server Script:

local PlayerListUpdate = Instance.new('RemoteEvent')
PlayerListUpdate.Name = 'PlayerListUpdate'
PlayerListUpdate.Parent = game.ReplicatedStorage


local Vals = {}


game.Players.PlayerAdded:connect(function(plr)
	local ls = Instance.new('IntValue')
	ls.Name = 'leaderstats'
	local kills = Instance.new('IntValue',ls)
	kills.Name = 'RoundKills'
	local killstreak = Instance.new('IntValue',ls)
	killstreak.Name = 'Killstreak'
	ls.Parent = plr
	Vals[plr.Name] = {
		kills:GetPropertyChangedSignal('Value'):connect(function()
			PlayerListUpdate:FireAllClients({
				['Action'] = 'Update',
			})
		end),
		killstreak:GetPropertyChangedSignal('Value'):connect(function()
			PlayerListUpdate:FireAllClients({
				['Action'] = 'Update',
			})
		end)
	}
end)

game.Players.PlayerRemoving:connect(function(plr)
	for i,v in ipairs(Vals[plr.Name]) do
		v:Disconnect()
	end
	Vals[plr.Name] = nil
end)

This should work for what you’re wanting! Hope it helps! :slight_smile:

1 Like

This was exactly what I needed! :slight_smile: thank you! Slight tweaking for some quirks in my game, but otherwise, this solved a problem that’s been bugging me for weeks. Many thanks!!

1 Like

Awesome! Glad to help. Best of luck with the game!

1 Like