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

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

Asked by 2 years ago

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)
0
forgot to mention that the PlayersModule is a ModuleScript tykoon3 5 — 2y

1 answer

Log in to vote
0
Answered by
xXMadonXx 190
2 years ago
Edited 2 years ago

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.

Ad

Answer this question