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

How can I modify this so that the system will always give you weapons until the round ended?

Asked by 1 year ago

Title says It all

local lobbyLocation = game.Workspace.SpawnLocation.Position + Vector3.new(0,3,0)



local ReplicatedStorage = game:GetService('ReplicatedStorage')

local timeEvent = ReplicatedStorage:WaitForChild('TimeEvent')

local roundEvent = ReplicatedStorage:WaitForChild('RoundEvent')



local function playGame()

    local timeAmount = 180

    local timerText = 'Remaining Time: '

    while timeAmount > 0 do

        timeEvent:FireAllClients(timeAmount, timerText)

        wait(1)

        timeAmount -= 1

    end

end



local function playIntermission()

    local intermission = 10

    local timerText = 'Intermission: '

    while intermission > 0 do

        timeEvent:FireAllClients(intermission, timerText)

        wait(1)

        intermission -= 1

    end

end



local function resetPlayers()

    for _, plr in pairs(game.Players:GetChildren()) do

        plr.Character.HumanoidRootPart.CFrame = CFrame.new(lobbyLocation)

        local CurrentMapFolder = game.Workspace.CurrentMap:GetChildren()

        for _, Map in ipairs(CurrentMapFolder) do

            if Map:IsA("Model") then

                Map:Destroy()

            end

        end

        local WeaponGiverFolder = game.Workspace.WeaponGivers:GetChildren()

        for _, Script in ipairs(WeaponGiverFolder) do

            if Script:IsA("Script") then

                Script.Enabled = false

            end

        end

    end 

end



local function teleportPlayers()

    for _, plr in pairs(game.Players:GetChildren()) do

        local RandomMap = math.random(1,1)

        if RandomMap == 1 then
            local OldSFOTHMap = game:GetService("ReplicatedStorage").Maps["Old SFOTH Map"]:Clone()
            OldSFOTHMap.Parent = game.Workspace
        end

        if RandomMap == 2 then
            local CubeSchool = game:GetService("ReplicatedStorage").Maps["Cube School"]:Clone()
            CubeSchool.Parent = game.Workspace
        end

        local WeaponGiverFolder = game.Workspace.WeaponGivers:GetChildren()

        for _, Script in ipairs(WeaponGiverFolder) do

            if Script:IsA("Script") then

                Script.Enabled = true

            end

        end

    end 

end



while true do

    resetPlayers()

    playIntermission()

    teleportPlayers()

    roundEvent:Fire()

    playGame()

end

1 answer

Log in to vote
0
Answered by 1 year ago

Try This

local lobbyLocation = game.Workspace.SpawnLocation.Position + Vector3.new(0,3,0)

local ReplicatedStorage = game:GetService('ReplicatedStorage')

local timeEvent = ReplicatedStorage:WaitForChild('TimeEvent')

local roundEvent = ReplicatedStorage:WaitForChild('RoundEvent')

local function playGame()
  local timeAmount = 180
  local timerText = 'Remaining Time: '
  while timeAmount > 0 do
    timeEvent:FireAllClients(timeAmount, timerText)
    wait(1)
    timeAmount -= 1
  end
end

local function playIntermission()
  local intermission = 10
  local timerText = 'Intermission: '
  while intermission > 0 do
    timeEvent:FireAllClients(intermission, timerText)
    wait(1)
    intermission -= 1
  end
end

local function resetPlayers()
  for _, plr in pairs(game.Players:GetChildren()) do
    plr.Character.HumanoidRootPart.CFrame = CFrame.new(lobbyLocation)
    local CurrentMapFolder = game.Workspace.CurrentMap:GetChildren()
    for _, Map in ipairs(CurrentMapFolder) do
      if Map:IsA("Model") then
        Map:Destroy()
      end
    end
  end
end

local function teleportPlayers()
  for _, plr in pairs(game.Players:GetChildren()) do
    local RandomMap = math.random(1,1)

    if RandomMap == 1 then
      local OldSFOTHMap = game:GetService("ReplicatedStorage").Maps["Old SFOTH Map"]:Clone()
      OldSFOTHMap.Parent = game.Workspace
    end

    if RandomMap == 2 then
      local CubeSchool = game:GetService("ReplicatedStorage").Maps["Cube School"]:Clone()
      CubeSchool.Parent = game.Workspace
    end

    local WeaponGiverFolder = game.Workspace.WeaponGivers:GetChildren()
    for _, Script in ipairs(WeaponGiverFolder) do
      if Script:IsA("Script") then
        Script.Enabled = true
      end
    end
  end
end

while true do
  resetPlayers()
  playIntermission()
  teleportPlayers()
  roundEvent:Fire()

  -- Keep giving weapons until the round ends
  while timeAmount > 0 do
    local WeaponGiverFolder = game.Workspace.WeaponGivers:GetChildren()
    for _, Script in ipairs(WeaponGiverFolder) do
      if Script:IsA("Script") then
        Script.Enabled = true
      end
    end
    wait(1)
  end

  playGame()
end

0
It doesn't work but I think I manage to find the problem, timeAmount Isn't a global variable, basically, the timeAmount variable Is Inside of the function, playGame() meaning, If the variable Is used anywhere besides playGame() Its not going to work, If that even makes sense imnotaguest1121 362 — 1y
Ad

Answer this question