New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

How do I freeze all players at the same time rather than individually?

Asked by 3 months ago

I'm trying to create a script where all players apart from the user who casted it, freeze at the same time. However, at the moment; The script freezes people individually, then after they unfreeze, moves onto the next person and then the next etc. But I want everyone to freeze at the same time otherwise the color correction doesn't match up..

Any ideas?

My code:

game.ReplicatedStorage.Freeze.OnServerEvent:Connect(function(player)
local TweenService = game:GetService("TweenService")
local part = game.Lighting.ColorCorrection
local Info = TweenInfo.new(
    10,
    Enum.EasingStyle.Linear,
    Enum.EasingDirection.Out,
    0,
    true,
    0)
local Goals ={
  Saturation = -1}
  local tween = TweenService:Create(part,Info,Goals)
  tween:Play()

  for _, child in ipairs(game.Players:GetChildren()) do
    if child.Name ~= player.Name then

      local Them = child.Character
wait()

      for _, NotThem in ipairs(Them:GetChildren()) do
    wait()
        if NotThem.ClassName == "Part" or NotThem.ClassName == "MeshPart" then
          NotThem.Anchored = true
        end
      end
wait(20)
for _, NotThem in ipairs(Them:GetChildren()) do
    wait()
        if NotThem.ClassName == "Part" or NotThem.ClassName == "MeshPart" then
          NotThem.Anchored = false
game.Lighting.ColorCorrection.Saturation = 0
        end
      end
    end
  end
  end)


Thank you.

1 answer

Log in to vote
1
Answered by
sleazel 679 Moderation Voter
3 months ago

Encapsulate the unfreeze in delay (it will create seperate threads for each player):

game.ReplicatedStorage.Freeze.OnServerEvent:Connect(function(player)
local TweenService = game:GetService("TweenService")
local part = game.Lighting.ColorCorrection
local Info = TweenInfo.new(
    10,
    Enum.EasingStyle.Linear,
    Enum.EasingDirection.Out,
    0,
    true,
    0)
local Goals ={
  Saturation = -1}
  local tween = TweenService:Create(part,Info,Goals)
  tween:Play()

for _, child in ipairs(game.Players:GetChildren()) do
    if child.Name ~= player.Name then
        local Them = child.Character
        wait()
        for _, NotThem in ipairs(Them:GetChildren()) do
            wait()
            if NotThem.ClassName == "Part" or NotThem.ClassName == "MeshPart" then
                NotThem.Anchored = true
            end
        end
        delay(20,function()
            for _, NotThem in ipairs(Them:GetChildren()) do
                wait()
                if NotThem.ClassName == "Part" or NotThem.ClassName == "MeshPart" then
                    NotThem.Anchored = false
                    game.Lighting.ColorCorrection.Saturation = 0
                    end
            end
        end)
    end
end

end)


Ad

Answer this question