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

Why is it not printing the player's name?

Asked by 10 years ago

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

Log in to vote
0
Answered by 10 years ago

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 .. "!"
Ad

Answer this question