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

How would I make a script to announce MULTIPLE winners?

Asked by 4 years ago

I've mostly figured out how to make a system to announce just one winner, but what about multiple. Background: I am making a minigames game, and different minigames have different types. I am going to explain two types here: Survival and OneSurvival. OneSurvival means that the last person left alive in the minigame will win, and their name will be announced. Survival means that everyone has to survive until the end, and if everyone dies before times up, it will be announced that there are no survivors. However, multiple people can survive in a Survival type minigame. Here is a code snippit:

function DoGame()
    local map = workspace.CurrentMap:FindFirstChildWhichIsA("Model")
    local roundlength = map:FindFirstChild("Time").Value
    local canwin = true

    if map:FindFirstChild("Type").Value == "Survival" then
        message.Value = "Time left: "..roundlength
        wait(1)
        repeat
            roundlength = roundlength - 1
            message.Value = "Time left: "..roundlength
        until roundlength == 0 or #workspace.InGame:GetChildren() == 0
        if #workspace.InGame:GetChildren() == 0 then
            message.Value = "No one has won :("
            wait(3)
        end
    end
end****

Here's some more context. "InGame" is a folder within the workspace that all players currently playing the minigame are in. I need a line in this script that will announce all the names of the survivors if there are multiple people alive when time is up. If you need more context, ask.

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

To elaborate on my comment to MrCatDoggo's answer, string concatenation through tables looks like this:

    local t = {}
    for i, c in ipairs(workspace.InGame:GetChildren()) do
        t[i] = c.Name
    end
    message.Value = "Survivors: " .. table.concat(t, ", ")

Notes:

  • prefer ipairs over `pairs
  • The second argument to table.concat is what will be placed between the different elements of the table (so in this case it'll say Player1 or Player1, Player2 or Player1, Player2, Player3)
Ad
Log in to vote
1
Answered by 4 years ago

I don't know if theres a quick way to do this, but I'd use this as a work around, in the appropiate place of course:

else
    local New = Instance.new("StringValue", workspace)

    for i,v in pairs(workspace.InGame:GetChildren()) do
        New.Value = New.Value .. v.Name .. ", "
    end

    message.Value = "The survivors were: " .. New.Value 
end

As said, this is a workaround as idk if theres something you can script manually for this

0
+1: This is the right idea, though the StringValue is unnecessary and using table concatenation (a bit more advanced) is easier chess123mate 5873 — 4y
0
Alright then MrCatDoggo 213 — 4y

Answer this question