Updating a Leaderstat value in a Gui via RemoteEvent?
Asked by
7 years ago Edited 7 years ago
Hello!
I have a Custom PlayerList, which displays a user's avatar, name, kills for that round, and a killstreak. So far, all the things work. Slight problem - the round kills/killstreak display only updates when the player dies/respawns, instead of as it happens.
There is a RemoteEvent inside ReplicatedStorage labeled as KillUpdate
Here's the LocalScript inside the ScreenGui under StarterGui for the Custom Player List:
01 | game.StarterGui:SetCoreGuiEnabled( "PlayerList" , false ) |
02 | local plr = game.Players.LocalPlayer |
03 | local kills = plr.leaderstats.Roundkills.Value |
04 | local killstreak = plr.leaderstats.Killstreak.Value |
09 | for _,plr in pairs (game.Players:GetChildren()) do |
10 | if script.Parent.Holder:FindFirstChild(plr.Name) then |
13 | local kills 2 = plr.leaderstats.Roundkills.Value |
14 | local killstreak 2 = plr.leaderstats.Killstreak.Value |
15 | I = Instance.new( "Frame" ) |
17 | I.Parent = script.Parent.Holder |
18 | I.Style = "DropShadow" |
20 | T = Instance.new( "TextLabel" ) |
22 | T.BackgroundTransparency = 1 |
25 | T.Size = UDim 2. new( 0 , 165 , 0 , 35 ) |
26 | T.Position = UDim 2. new( 0 , 10 , 0 , 0 ) |
27 | if plr.Name = = game.Players.LocalPlayer.Name then |
28 | T.TextColor 3 = Color 3. fromRGB( 0 , 200 , 255 ) |
30 | T.TextColor 3 = Color 3. new( 1 , 1 , 1 ) |
32 | T.TextStrokeColor 3 = Color 3. new( 0 , 0 , 0 ) |
33 | T.TextStrokeTransparency = 0.5 |
34 | T.TextXAlignment = "Left" |
35 | T.Font = "SourceSansBold" |
38 | K = Instance.new( "TextLabel" ) |
40 | K.BackgroundTransparency = 1 |
43 | K.Size = UDim 2. new( 0 , 20 , 0 , 35 ) |
44 | K.Position = UDim 2. new( 0 , 155 , 0 , 0 ) |
45 | K.TextColor 3 = Color 3. new( 1 , 1 , 1 ) |
46 | K.TextStrokeColor 3 = Color 3. new( 0 , 0 , 0 ) |
47 | K.TextStrokeTransparency = 0.5 |
48 | K.TextXAlignment = "Right" |
49 | K.Font = "SourceSansBold" |
60 | local event = game:GetService( "ReplicatedStorage" ):WaitForChild( "KillUpdate" ) |
61 | K.Changed:connect( function () |
62 | local amountOfKills = K.Text |
63 | event:FireServer(amountOfKills) |
Script inside ServerScriptStorage:
1 | local event = game:GetService( "ReplicatedStorage" ):WaitForChild( "KillUpdate" ) |
2 | event.OnServerEvent:connect( function (player,amountOfKills) |
3 | player.leaderstats.Roundkills.Value = amountOfKills |