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

How to play a for loop at the same time instead of consequitively?

Asked by 1 year ago

Currently I am working on a game that is pretty similar to the hunger games, for each district they have a platform that needs to be risen. I access each platform using a script like below:

for i, Players in pairs(Playerz:GetChildren()) do
    if Players.DistrictCode then
        Players.Character.HumanoidRootPart.CFrame =             game.Workspace.Pedestals[Players.DistrictCode.Value].Plate.CFrame + Vector3.new(0, 4, 0)
        Players.Character.Humanoid.Speed = 0
    end
    for i = 1, 451 do 
        game.Workspace.Pedestals[Player.DistrictCode.Value].Plate.CFrame += CFrame.new(0, 0.1, 0)
        wait(0.01)
    end
end

Unfortunately my problem is that when I'm using this code instead of all the platforms raising simultaneously, they do it consequietively due to the for loop at the very start and the wait(0.01) part, which goes through each players districtcode and rises it before moving onto the next. I need all platforms to raise at the same time. I know a solution could be to code each platform to raise individually , but I believe there could be a more efficient method to rising the platforms at the same time.

0
maybe use CollectionService or put them into 2 different scripts, that's just off the top of my head tho ZeroToH3ro 82 — 1y

Answer this question