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

How do i name all players without one at a time?

Asked by 7 years ago

I'm trying to make it so it tells the players name an i want it like this "Winners: UltraUnitMode, Guest666, ROBLOX" if you know what i mean, so far i can only do it one at a time so it goes like this "Winners: UltraUnitMode" waits a second "Winners: Guest666" so on, hence the wait. Also I'm not sure if tostring() is a good idea to make it do that? Idk so thats why im asking lol

function LookForWinner()
local Players = game.Players:GetChildren()
for i = 1, #Players do
if Players[i]:FindFirstChild('leaderstats') then
if Players[i].leaderstats.KOs.Value >= 25 then
Message('Winners: '..Players[i].Name) -- Sends into the function and changes the text for everyone
wait(1)
end
end
end
end

0
That's one heck of a run-on sentence. And no, you would have to use a Loop to get and rename all the players. User#11440 120 — 7y

1 answer

Log in to vote
0
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
7 years ago

Since you're not dealing with a Table, you have to use string concatenation in a loop:

function LookForWinner()
    local winners = ""

    for _, player in ipairs(game.Players:GetChildren()) do
        if player:FindFirstChild('leaderstats') and player.leaderstats.KOs.Value >= 25 then
            winners = winners .. (#winners > 0 and ", " or "") .. player.Name
        end
    end

    Message('Winners: ' .. winners)
    wait(1)
end
Ad

Answer this question