Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

Custom Player List - update all users?

Asked by 2 years ago
Edited 2 years ago

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

1 answer

Log in to vote
1
Answered by
Nonaz_jr 439 Moderation Voter
2 years ago
Edited 2 years ago

first off, you do this every second? making a whole new unupdated gui (using values read at initialization, such as killstreak, then waiting for the event to update it? I may misunderstand, I read it quickly.

Without the while loop, it's decent but it doesn't know which player to update: The event sends only a new value, but not the player to whom it applies. You should have it send a second argument, indicating which stat to update in the gui:

game:GetService("ReplicatedStorage"):WaitForChild("KillStreakUpdate").OnClientEvent:Connect(function(updatedPlayer, value)
    if(updatedPlayer.Name == plr.Name) then
        KS.Text = value
    end
end)

And of course the same for the killupdate, and also update the remote event code:


local updatedPlayer = <a way to know which player's killstreak was changed> game:GetService("ReplicatedStorage"):WaitForChild("KillStreakUpdate"):FireClient(Player, updatedPlayer, Killstreak.Value)

Edit: added code block

Edit 2: The changed code you asked:

--event script:
game:GetService("ReplicatedStorage"):WaitForChild("KillStreakUpdate"):FireAllClients(Player.Name, Killstreak.Value)
--localscript:
game:GetService("ReplicatedStorage"):WaitForChild("KillStreakUpdate").OnClientEvent:Connect(function(updatedPlayerName, value)
    if(updatedPlayerName == plr.Name) then --<removed the dot!
        KS.Text = value
    end
end)
0
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 Never2Humble 81 — 2y
1
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 Nonaz_jr 439 — 2y
0
^ I updated my main post with the edits, but its still not updating the stats in real time for the player list. Never2Humble 81 — 2y
1
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 Nonaz_jr 439 — 2y
View all comments (3 more)
0
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 Nonaz_jr 439 — 2y
0
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 Nonaz_jr 439 — 2y
0
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! Nonaz_jr 439 — 2y
Ad

Answer this question