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

Why won't my server message display the top survivors name?

Asked by
JipSea 23
4 years ago

Hello!

I am currently making a game that will display the TOP SURVIVORS name on the top of the screen, but it is not working .Here's what I have so far:

h = Instance.new("Hint") 
h.Parent = game.Workspace 
highscore = 0 
highscorename = "Nobody" 

while true do 
wait(0.01) 
local l = game.Players:children() 
for i=1,#l do 
local bounce = l[i].leaderstats:findFirstChild("Seconds") 
if (bounce ~= nil) then 
if (bounce.Value > highscore) then 
highscore = bounce.Value 
highscorename = l[i].leaderstats.Parent.Name 
h.Text = "Server's longest survivor: "..highscore..", made by: "..highscorename.."!" 
end 
end 
end 
end 

I know I am missing something. Any help would be appreciated, TY

-JIP

0
:Children() is deprecated, dont use it Kriscross102 118 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

One thing you can do is change your use of for i=1,#l and use `for i,v in pairs'

That would look something like this with your code:

local hint = Instance.new("Hint", workspace)
hint.Text = ""
Highscore = 0
PlayerWithScore = ""

while wait() do --This is better than while true do then wait(0.01)
    local Plrs = game.Players:GetChildren()

    for i,v in pairs(Plrs) do
        local ls = v:WaitForChild("leaderstats")
        local Secs = ls:WaitForChild("Seconds")
        if Secs.Value > Highscore then
            Highscore = Secs.Value
            PlayerWithScore = v.Name
        end
    end

    hint.Text = "Server's longest survivor: "..tostring(Highscore)..", made by: "..PlayerWithSocre.."!"
end

Try that out

0
AMAZING TY! JipSea 23 — 4y
0
Np lol MrCatDoggo 213 — 4y
Ad

Answer this question