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

Why is it not printing the player's name?

This script is suppose to create a hint if not familliar its a gui then loop through the players and if there streak is greater then the highest streak it will print there name. in Simple if you have the higheststreak your name will be up top but it doesn't print player name. ERROR:STREAK IS NOT A VALID MEMBER OF PLAYER.

hint=Instance.new("Hint") 
hint.Parent=workspace 
hint.Name="LargestStreak" 
while true do 
highestStreak=0 
p="" 
for _,player in pairs(game.Players:GetChildren()) do 
if player.streak.Value>highestStreak then 
p=player.Name 
highestStreak=player.streak.Value 
end 
end 
hint.Text=p.." has the biggest streak with the kill streak of "..highestStreak.."!" 
wait() 
end

1 answer

The problem is you put everything into a while true do loop. No need for that. Especially when your loop was resetting itself several hundred times per second.

Try this, instead:

local hint = Instance.new("Hint", workspace)
hint.Name = "LargestStreak"

local highestStreakOwner
for _,player in ipairs(game.Players:GetChildren()) do
	if player.streak.Value > highestStreakOwner.streak.Value then
		highestStreakOwner = player
	end
end

hint.Text = highestStreakOwner.Name .. " has the biggest streak with a kill streak of " .. highestStreakOwner.streak.Value .. "!"

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