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

Get playernames if bool = false?

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

✓ Accepted answer
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})

2 comments

0

thx

0

You are welcome!

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!

2 comments

0

@tiraner300 's way of adding to a table and sending the list to chat as a string is better

0

Thanks, your is pretty effective too!

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