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

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

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

1 comment

0

:Children() is deprecated, dont use it

1 answer

✓ Accepted answer

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

2 comments

0

AMAZING TY!

0

Np lol

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