I’m trying to make a system that would update the player with most KOs on a GUI, but I can’t find a way to do that, certain scripting concepts confuse me, and I’m often lost looking at the API and looking at the dev forums with no luck.
Well to detect when a player kills someone gets a little complicated to explain in a single reply, however, have you tried looking up tutorials on like a Kills + deaths leaderboard (you can remove the deaths yourself)
Well, I already kind of have that leaderboard. My issue is trying to access the leaderstats, and from there; find the player with most kills, and put their username on the GUI.

Ok, so basically what you want is a local script in the UI, a remote event in ReplicatedStorage (called: UpdateMVP) and you want to add something to your leaderstats script:
Local Script In UI:
local event = game:GetService("ReplicatedStorage").UpdateMVP
local Players = game:GetService("Players")
event.OnClientEvent:Connect(function()
local Plrs = Players:GetPlayers()
local MVP = nil
for _, player in pairs(Plrs)
local PlrGui = player.PlayerGui
local ScreenUi = PlrGui.ScreenGui
local Label = ScreenUi.Label
local leaderstats = player.leaderstats
local kills = leaderstats.kills
if MVP then
if kills.Value > MVP.leaderstats.kills.Value then MVP = player end
else
MVP = player
end
Label.Text = "MVP: "..tostring(MVP)
end
end)
In your leaderstats:
kills.Changed:Connect(function()
game.ReplicatedStorage.UpdateMVP:FireAllClients()
end)
Thank you! I’m not the best at scripting, and especially when it comes to functions and stuff, I’m trying to learn but it’s really hard; shall I credit you in the description of my game for this?
Nah no need.
Well ain’t that convenient, I currently have a scripting series going, that I’ve been uploading this week (and will continue uploading), so far we have covered: Variables, Properties, Instance.new(), Functions, If statements, and today at 12:00pm est Loops
Okay! How do you get good at scripting by the way? I try my best to learn and follow along tutorials and understand the concepts to put together a script; but sometimes, I kind of get lost and confused as to what’s happening in the script itself.
Well, when I first started I started with a scripting series, after that I watched tutorials on how to make specific types of games, but with each script I would try to understand and even tweak some things. Finally, I just tried things myself and when I got stuck I’d look to google, mostly on the DevForum (and sometimes the DevHub aswell)
Alright, thank you!
also, I can’t seem to get the GUI to do anything; no errors are in the output aswell, so I can’t see what’s wrong…
Can I see your whole leaderstats script
P.S : My game comes from an old roblox game; so a lot of the scripts aren’t mine.
function onPlayerEntered(newPlayer)
local TKs = Instance.new("IntValue")
TKs.Name = "TeamKills"
TKs.Value = 0
TKs.Parent = newPlayer
local stats = Instance.new("IntValue")
stats.Name = "leaderstats"
kills = Instance.new("IntValue")
kills.Name = "KOs"
kills.Value = 0
local deaths = Instance.new("IntValue")
deaths.Name = "Wipeouts"
deaths.Value = 0
kills.Parent = stats
deaths.Parent = stats
-- VERY UGLY HACK
-- Will this leak threads?
-- Is the problem even what I think it is (player arrived before character)?
while true do
if newPlayer.Character ~= nil then break end
wait(5)
end
local humanoid = newPlayer.Character.Humanoid
humanoid.Died:connect(function() onHumanoidDied(humanoid, newPlayer) end )
-- start to listen for new humanoid
newPlayer.Changed:connect(function(property) onPlayerRespawn(property, newPlayer) end )
stats.Parent = newPlayer
end
function Send_DB_Event_Died(victim, killer)
– killer may be nil
local killername = “no one”
if killer ~= nil then killername = killer.Name end
print("DIED EVENT: ", victim.Name, " KILLED by ", killername)
if shared["deaths"] ~= nil then
shared["deaths"](victim, killer)
print("SENT DB DEATH EVENT")
end
end
function Send_DB_Event_Kill(killer, victim)
print("KILL EVENT. ", killer.Name, " BLOXXED ", victim.Name)
if shared[“kills”] ~= nil then
shared[“kills”](killer, victim)
print(“SENT DB KILL EVENT”)
end
end
function onHumanoidDied(humanoid, player)
local stats = player:findFirstChild(“leaderstats”)
if stats ~= nil then
local deaths = stats:findFirstChild(“Wipeouts”)
deaths.Value = deaths.Value + 1
-- do short dance to try and find the killer
local killer = getKillerOfHumanoidIfStillInGame(humanoid)
--checkTKs(player, killer)
Send_DB_Event_Died(player, killer)
handleKillCount(humanoid, player)
end
end
function onPlayerRespawn(property, player)
– need to connect to new humanoid
if property == "Character" and player.Character ~= nil then
local humanoid = player.Character.Humanoid
local p = player
local h = humanoid
humanoid.Died:connect(function() onHumanoidDied(h, p) end )
end
end
function getKillerOfHumanoidIfStillInGame(humanoid)
– returns the player object that killed this humanoid
– returns nil if the killer is no longer in the game
-- check for kill tag on humanoid - may be more than one - todo: deal with this
local tag = humanoid:findFirstChild("creator")
-- find player with name on tag
if tag ~= nil then
local killer = tag.Value
if killer.Parent ~= nil then -- killer still in game
return killer
end
end
return nil
end
function handleKillCount(humanoid, player)
local killer = getKillerOfHumanoidIfStillInGame(humanoid)
if killer ~= nil then
local stats = killer:findFirstChild(“leaderstats”)
if stats ~= nil then
local kills = stats:findFirstChild(“KOs”)
if killer ~= player then
kills.Value = kills.Value + 1
else
kills.Value = kills.Value - 0
end
Send_DB_Event_Kill(killer, player)
end
end
end
game.Players.ChildAdded:connect(onPlayerEntered)
kills.Changed:Connect(function()
game.ReplicatedStorage.UpdateMVP:FireAllClients()
end)
You have to move that to the OnPlayerEntered function. Speaking of which:
Should be game.Players.PlayerAdded
Ah, it works now! Thank you.
Unrelated to this post’s topic; but I’m having trouble understanding things like adding variables in functions ex.
function(hit) and hit.Parent and other things like that. As much as I try to adapt to those concepts and understands them I end up getting frustrated at the fact that I can’t understand them.
Great, mark the solution!
Those are called parameters, I suggest you check out my video on understanding functions:
Thank you very much. Do you think it’s possible for me to learn programming in a state like this?
What do you mean by “a state like this”.
What I mean is; being unable to understand certain concepts such as the i,v in pairs concepts or any concept that I may find difficult to understand.
Yep, for functions I explained them in the video I linked you.
I have a video releasing in just under 1 hour that will cover all the types of loops.
- i, v in pairs
- for i
- while loop
- repeat wait until
- Recursive functions
Okay, thanks! I subscribed. : )
After testing it again, it seems that it only updates on the player’s screen locally, and not for other players. I know this is because it’s in a local script, but if it weren’t in a local script it would be impossible to get the LocalPlayer, I don’t know how to fix this.