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

How do i make this happen for all players at the same time?

Asked by 7 years ago

It starts for one player then when its done it starts for another player. But how do i make it start for all players at the same time?

for i,v in pairs(game.Players:GetChildren()) do
         v.PlayerValues.Playing.Value = true 
        if MazeClone.Name == "Classic" then
                    v.PlayerGui.GameGui.Map.MapImage.Image = ""
                    v.PlayerGui.GameGui.Map.MapName.Text = "Classic  Maze"
                    v.PlayerGui.GameGui.Map.MapCreator.Text = "Made by Prismous"
                    v.PlayerGui.GameGui.Map:TweenPosition(UDim2.new(0.5, -220, 0.5, -140), "Out", "Quad", 1, true)
                    wait(6)
                    v.PlayerGui.GameGui.Map:TweenPosition(UDim2.new(0.5, -220, -0.5, -140), "Out", "Elastic", 1.4, true)

                  end
    end
          for i, players in pairs(game:GetService("Players"):GetPlayers()) do
             if players.Character and players.Character:FindFirstChild("Torso") then
                players.Character.Torso.CFrame = Ctarget + Vector3.new(0 , 0 , i*math.random(1,5))
            end
    end

2 answers

Log in to vote
2
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
7 years ago
Edited 7 years ago

Here is the sequence of actions (I think) that you want to happen:

  1. All players see transition in
  2. wait 6 seconds
  3. All players see transition out
  4. All players get teleported

In that case, do that:

for _, player in pairs(game.Players:GetPlayers()) do
    transitionIn(player)
end

wait(6)

for _, player in pairs(game.Players:GetPlayers()) do
    transitionOut(player)
end

for i, player in pairs(game.Players:GetPlayers()) do
    teleport(player, i)
end

(The helper functions transitionIn, transitionOut, and teleport would be something like this, extracted from your original code:)


function transitionIn(player) player.PlayerValues.Playing.Value = true -- Show transition player.PlayerGui.GameGui.Map.MapImage.Image = "" player.PlayerGui.GameGui.Map.MapName.Text = "Classic Maze" player.PlayerGui.GameGui.Map.MapCreator.Text = "Made by Prismous" player.PlayerGui.GameGui.Map:TweenPosition(UDim2.new(0.5, -220, 0.5, -140), "Out", "Quad", 1, true) end function transitionOut(player) player.PlayerGui.GameGui.Map:TweenPosition(UDim2.new(0.5, -220, -0.5, -140), "Out", "Elastic", 1.4, true) end function teleport(player, i) if player.Character and players.Character:FindFirstChild("Torso") then player.Character.Torso.CFrame = Ctarget + Vector3.new(0 , 0 , i * 5)) end end

Style

Tab and space your code correctly.

You should use :GetPlayers() and not :GetChildren().

You should use FilteringEnabled in all your games. This script will not work with FilteringEnabled, because Script objects do not have access to any players' PlayerGui. If you structure you code so that it is small and readable (e.g., broken it into functions the way I have) then it is easy to convert.

Use meaningful names. v is a terrible name for a player. players is also a terrible name for something which isn't a list of players.

You don't need coroutines for something so procedural.

0
Ill try this out, thanks. supermanswaqq 65 — 7y
Ad
Log in to vote
-1
Answered by
einsteinK 145
7 years ago

Use a coroutine or use spawn:

for i,v in pairs(game.Players:GetChildren()) do
    spawn(function()
        -- rest of code
    end)
end
0
...That is definitely not the right way to approach this BlueTaslem 18071 — 7y
0
Do you have a wiki link? supermanswaqq 65 — 7y
0
Yea, this is not the correct way to do it because, your function will just double and it will be like adding more then the value you wanted to be added. So, this wouldn't be a good idea. KingLoneCat 2642 — 7y

Answer this question