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

How to make for loop for each player and return players with specific values to remote?

I'm trying to create a function that grabs each player that specifically has a leaderstat called Alive set to true. Then I need it to print out the results to a remote to send to the players. Although, with the script I have it just prints everyones name no matter what. I'm not sure what I'm doing wrong.

Codes: PlayersModule:

function player.getPlayers()
	local alive = {}
	for i, v in pairs(game.Players:GetChildren()) do
		if (v.leaderstats.Alive.Value == true) then
			table.insert(alive,v.Name)
			v.leaderstats.Points.Value = v.leaderstats.Points.Value + 25
		end
	end
	return alive
end

Game:

		if (g == 'intermission' and s == 0) then
			if (game.Workspace:FindFirstChild("disaster")) then
				local grabby = player.getPlayers()
				local grabbytable = table.concat(grabby, ',')
				returnPlayers:FireAllClients(grabbytable)
				game.Workspace.disaster:Destroy()
			end

LocalScript:

disaster.OnClientEvent:Connect(function(s)
disastertext.Text = s
	print(s)
	frame.Visible = true
	wait(5)
	frame.Visible = false


end)

1 comment

0

forgot to mention that the PlayersModule is a ModuleScript

1 answer

The script is fine and works as expected by only passing alive (by Value) players.

My guess: The code where the value of Alive is changed is the faulty code.

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