How would I be able to make a leaderboard that has "Wins", "KO's", and "Points"? When a player enters that person would start out with 25 Points and that the leaderboard wouldn't break. I'm not sure I would set this up, could someone help me?
COMMUNITY QUESTION
How would I be able to make a leaderboard that works properly?
3 answers
game.Players.PlayerAdded:connect(function(plr)
local stat = Instance.new("Model", plr)
stat.Parent = plr
local win = Instance.new("IntValue", plr.stat)
win.Value = 0
win.Name = "Wins"
local Ko = Instance.new("IntValue", plr.stat)
Ko.Value = 0
Ko.Name = "KOs" --If Put the ' ' then it will think that it made another string inside the string
local Points = Instance.new("IntValue", plr.stat)
Points.Value = 25
Points.Name = "Points"
end)
HOWEVER IT CAN STILL CRASH IF THE PLAYER LAGS MEANING THEY WONT SPAWN IN THE GAME WITH THOSE STATS. THERE IS NO WAY TO FIX THAT
Also can the KO's work like the KO's do normally on a leaderboard? I forgot to say that, sorry.
2 comments
0
If so copy it out of the basic leaderboard and insert a model into the player because thats the grey holder thing
0
The leaderboard just breaks..
function onPlayerEntered(newPlayer)
local stats = Instance.new("IntValue")
stats.Name = "leaderstats"
local kills = Instance.new("IntValue")
kills.Name = "KOs"
kills.Value = 25
local deaths = Instance.new("IntValue")
deaths.Name = "Wipeouts"
deaths.Value = 0
kills.Parent = stats
deaths.Parent = stats
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 )
newPlayer.Changed:connect(function(property) onPlayerRespawn(property, newPlayer) end )
stats.Parent = newPlayer
end
function Send_DB_Event_Died(victim, killer)
local killername = "no one"
if killer ~= nil then killername = killer.Name end
if shared["deaths"] ~= nil then
shared["deaths"](victim, killer)
end
end
function Send_DB_Event_Kill(killer, victim)
if shared["kills"] ~= nil then
shared["kills"](killer, victim)
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
local killer = getKillerOfHumanoidIfStillInGame(humanoid)
Send_DB_Event_Died(player, killer)
handleKillCount(humanoid, player)
end
end
function onPlayerRespawn(property, player)
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)
local tag = humanoid:findFirstChild("creator")
if tag ~= nil then
local killer = tag.Value
if killer.Parent ~= nil then
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
end
Send_DB_Event_Kill(killer, player)
end
end
end
game.Players.ChildAdded:connect(onPlayerEntered)
Spend all of time for this :3
Remember to Upvote meh :3
Hope it helps.... :)
1 comment
0
Dont use ToTo's it has alot of things wrong with it.
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
Question, my game doesn't lag for me and most players so far but when I test it with just me and a friend, it appears he is lagging on my screen and im lagging on his screen but neither of us are lagging on our own screens. Do you think this could affect us?
Also, why insert a model into the player?