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
Here is the sequence of actions (I think) that you want to happen:
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
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.
Use a coroutine or use spawn:
for i,v in pairs(game.Players:GetChildren()) do spawn(function() -- rest of code end) end