Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Updating a Leaderstat value in a Gui via RemoteEvent?

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:

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="

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 Stuff

-- AVATAR IMAGE Stuff


-- REMOTE EVENT CALL:

local event = game:GetService("ReplicatedStorage"):WaitForChild("KillUpdate")
K.Changed:connect(function()
    local amountOfKills = K.Text
    event:FireServer(amountOfKills)
print("Test1")


end)
end
end
end

Script inside ServerScriptStorage:

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

1 answer

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

local event=game:GetService("ReplicatedStorage"):WaitForChild("KillUpdate")

gui.TextLabel.Changed:connect(function()
	
	local amountOfKills=gui.TextLabel.Text
	event:FireServer(amountOfKills)

end)

server script

local event=game:GetService("ReplicatedStorage"):WaitForChild("KillUpdate")

event.OnServerEvent:connect(function(player,amountOfKills)

	player.leaderstats.Kills.Value=amountOfKills 

end)

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)


local event = game:GetService("ReplicatedStorage"):WaitForChild("KillUpdate")
local client=game:GetService("ReplicatedStorage"):WaitForChild("GUIKillUpdate")
event.OnServerEvent:connect(function(player,amountOfKills)

    player.leaderstats.Roundkills.Value = amountOfKills
	client:FireClient(player,amountOfKills)

end)

and in a local script inside the player gui put this

local client=game:GetService("ReplicatedStorage"):WaitForChild("GUIKillUpdate")

client.OnClientEvent:connect(function(player,amountOfKills)

	killtext.Text=amountOfKills
	--change the killtext to whatever the gui is and make it get to the textlabel 
end)

6 comments

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?

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

0

What I wrote will constantly update a players kills when they get one

0

Right. But its not updating the gui in real time, the gui text only updates for the player after they've died/respawned.

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.

0

Check the edit

This discussion is preserved as it was. New answers, comments, and votes are closed.