Hello!
I have a custom player list, and the custom player list will display a player's: Avatar, Name, Round Kills, and Killstreak. Only problem is, it doesn't update the Round Kills/Killstreak for the correct user in real time.
Example: Player 1 has 2 RoundKills and a Killstreak of 2. On Player 1's Display, it shows these stats belonging to Player 2 instead of the actual player. How do I fix this? I know I need it to check for all the players, but I'm not sure how to do that correctly, my prior attempts have failed.
In my Leaderstats script I have this bit of code:
local updatedPlayerKillstreak = game:GetService("ReplicatedStorage"):WaitForChild("KillStreakUpdate")
game:GetService("ReplicatedStorage"):WaitForChild("KillStreakUpdate"):FireClient(Player, updatedPlayerKillstreak, Killstreak.Value)
print("Killstreak check")
local updatedPlayerKills = game:GetService("ReplicatedStorage"):WaitForChild("KillUpdate")
game:GetService("ReplicatedStorage"):WaitForChild("KillUpdate"):FireClient(Player, updatedPlayerKills, Roundkills.Value)
print("RoundKills check")
And under StarterGui I have my ScreenGui named "PlayerList" and a Local Script under that named "Main", this is the script below:
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
-- 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(updatedPlayerKills, value)
if(updatedPlayerKills.Name == plr.Name) then K.Text = value
end
end)
game:GetService("ReplicatedStorage"):WaitForChild("KillStreakUpdate").OnClientEvent:Connect(function(updatedPlayerKillstreak, value)
if(updatedPlayerKillstreak.Name == plr.Name) then KS.Text = value
end
end)
end
end
end

7 comments
o.o This looks good, but a tad confusing, can you put your script in the LUA block code so I can be sure I have it correct. Mainly, the last bit of code you did is popping up with errors, you didn't establish what local updatedPlayer is. Unless I'm misunderstanding. Thank you for your response btw!! :D
So as you see in line 1 of the 2nd script there is "local updatedPlayer = <a way to know which player's killstreak was changed>": here you must add a bit of code of yourself to get the player whose killstreak etc must be updated
^ I updated my main post with the edits, but its still not updating the stats in real time for the player list.
So if this "Roundkills" in Roundkills.Changed:Connect(function() is a leaderstat numbervalue, it should not be so hard to find a reference to the player, who is leaderstats.Parent
I don't see the problem right now. In any case, you should comment out line 2,3,4 of your localscript cause it's confusing, and try not to use the same variable name twice. it should use the right one here though
it seems to me that the different players' stats are all in the same place in your gui (i.e. overlapping): I.Position = UDim2.new(0, 0, 0, nrOfButtons*buttonSizePlusOffset); nrOfButtons +=1 etc
and make sure that the event firing is properly connected to the changing of the numbervalue in leaderstats, by the part of the script you didnt show, and confirm that this numbervalue is indeed changed in your tests. is the new value passed to localscript? Good luck!