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

Get playernames if bool = false?

Asked by 6 years ago
for i,v in pairs(game.Players:GetChildren()) do
    if v.PlayerGui.MainGui.Values.Died.Value == false then    
        -- what do I write here
    end
end

What do I write there?? I want a message on the screen saying playernames did survive! How do I collect all names of the player having the value set to false?

2 answers

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago
local text
local PlayersSurvived = {}

for i,v in pairs(game.Players:GetChildren()) do
    if v.PlayerGui.MainGui.Values.Died.Value == false then    
        table.insert(PlayersSurvived, v.Name)
    end
end

text = table.concat(PlayersSurvived, ", ") .. "did survive!"

game.StarterGui:SetCore("ChatMakeSystemMessage", {Text = text})
0
thx GroovyFhish 8 — 6y
0
You are welcome! Le_Teapots 913 — 6y
Ad
Log in to vote
0
Answered by
Nonaz_jr 439 Moderation Voter
6 years ago

First off, you're gonna want to be real careful if this is not a localscript.. If it is then it's all good, as it's gonna write on the players screen anyway, as long as the BoolValue 'Died' was set correctly locally for all players.

In any case, I guess you want to add the players to a list that hv the value set to false:


playersNotDied = {} for i,v in pairs(game.Players:GetChildren()) do if v.PlayerGui.MainGui.Values.Died.Value == false then playersNotDied[#PlayerNotDied +1] = v end end print("Nr of players who survived: "..#playersNotDied for i,v in pairs(playersNotDied) do print v.Name end

Either store their names in a list then use that list later, or just directly:

survivedMessage= "Players survived: "
for i,v in pairs(game.Players:GetChildren()) do
    if v.PlayerGui.MainGui.Values.Died.Value == false then    
        survivedMessage = survivedMessage..v.Name.." "
    end
end
print(survivedMessage)

Add the names to your string. You can then display the string on the screen by setting the value of your textlabel in your GUI to the value of this string. Good luck!

0
@tiraner300 's way of adding to a table and sending the list to chat as a string is better Nonaz_jr 439 — 6y
0
Thanks, your is pretty effective too! Le_Teapots 913 — 6y

Answer this question