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?
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})
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!