Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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:

01game.StarterGui:SetCoreGuiEnabled("PlayerList", false)
02local plr = game.Players.LocalPlayer
03local kills = plr.leaderstats.Roundkills.Value
04local killstreak = plr.leaderstats.Killstreak.Value
06 
07while wait(1) do
08 
09    for _,plr in pairs (game.Players:GetChildren()) do
10        if script.Parent.Holder:FindFirstChild(plr.Name) then
11 
12        else
13            local kills2 = plr.leaderstats.Roundkills.Value
14            local killstreak2 = plr.leaderstats.Killstreak.Value
15            I = Instance.new("Frame")
View all 70 lines...

Script inside ServerScriptStorage:

1local event = game:GetService("ReplicatedStorage"):WaitForChild("KillUpdate")
2event.OnServerEvent:connect(function(player,amountOfKills)
3    player.leaderstats.Roundkills.Value = amountOfKills
4end)

1 answer

Log in to vote
1
Answered by 7 years ago
Edited 7 years ago

You can have an event fire everytime your kills/killstreak changes, here's an example but you're gonna have to change it to fit your script. also you need to make an event and put it in replicated storage and call it KillUpdate local script

1local event=game:GetService("ReplicatedStorage"):WaitForChild("KillUpdate")
2 
3gui.TextLabel.Changed:connect(function()
4 
5    local amountOfKills=gui.TextLabel.Text
6    event:FireServer(amountOfKills)
7 
8end)

server script

1local event=game:GetService("ReplicatedStorage"):WaitForChild("KillUpdate")
2 
3event.OnServerEvent:connect(function(player,amountOfKills)
4 
5    player.leaderstats.Kills.Value=amountOfKills
6 
7end)

If you have any questions let me know. EDIT Here's your server script (make a remote event called GUIKillUpdate and put it in replicated storage)

1local event = game:GetService("ReplicatedStorage"):WaitForChild("KillUpdate")
2local client=game:GetService("ReplicatedStorage"):WaitForChild("GUIKillUpdate")
3event.OnServerEvent:connect(function(player,amountOfKills)
4 
5    player.leaderstats.Roundkills.Value = amountOfKills
6    client:FireClient(player,amountOfKills)
7 
8end)

and in a local script inside the player gui put this

1local client=game:GetService("ReplicatedStorage"):WaitForChild("GUIKillUpdate")
2 
3client.OnClientEvent:connect(function(player,amountOfKills)
4 
5    killtext.Text=amountOfKills
6    --change the killtext to whatever the gui is and make it get to the textlabel
7end)
0
Thank you for your response! I edited my original post with the updated script, no error outputs, but its still not updating the Kill digit on the screengui. Do I have this wrong? Never2Humble 90 — 7y
0
^ Actually, since adding the remote event, its increase the RoundKill.Value of the player who is killed in addition to the killer's RoundKill.Value Never2Humble 90 — 7y
0
What I wrote will constantly update a players kills when they get one Earthkingiv 51 — 7y
0
Right. But its not updating the gui in real time, the gui text only updates for the player after they've died/respawned. Never2Humble 90 — 7y
View all comments (2 more)
0
I'm sure the problem is in how I implemented your script, would you mind taking a once over look? I updated my main post with your script. I'm sure i did something wrong, as your script looks like it should work without a hitch. Never2Humble 90 — 7y
0
Check the edit Earthkingiv 51 — 7y
Ad

Answer this question