I have a game that’s similar to Evade where a random map is picked, a random monster is picked, and everyone teleports to the map. Then after 3 minutes, everything unloads and a new map & monster are picked any everything loops all over again. Everything in this script works perfectly fine, but the script doesn’t loop. Instead of a while loop, I tried to use:
for i = 1, 1000 do
-- The code here
end
but the script still didn’t loop. The script below is what I need help with. This is a regular script inside ServerScriptService.
-- This script goes in ServerScriptService
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ReplicatedFirst = game:GetService("ReplicatedFirst")
local Lighting = game:GetService("Lighting")
local Workspace = game:GetService("Workspace")
local RunService = game:GetService("RunService")
local maps = ReplicatedStorage.Maps
local junkyardMap = maps.JunkyardMap
local warehouseMap = maps.WarehouseMap
-- Set time of day to midnight
Lighting.ClockTime = 0
while true do
-- Randomly pick a map to move into Workspace and out of ReplicatedStorage
local mapToLoad = math.random() >= 0.5 and junkyardMap or warehouseMap
mapToLoad.Parent = Workspace
if mapToLoad == junkyardMap then
-- Randomly pick one monster and spawn it at JunkyardMap coordinates
local monster = math.random(1, 6)
local monsterClone = ReplicatedStorage["Monster" .. monster]:Clone()
monsterClone.Parent = Workspace
monsterClone:SetPrimaryPartCFrame(CFrame.new(352, 7, 505))
elseif mapToLoad == warehouseMap then
-- Randomly pick one monster and spawn it at WarehouseMap coordinates
local monster = math.random(1, 6)
local monsterClone = ReplicatedStorage["Monster" .. monster]:Clone()
monsterClone.Parent = Workspace
monsterClone:SetPrimaryPartCFrame(CFrame.new(-859, 7, -20))
end
-- Move the LoadingScreenScript to ReplicatedFirst if it's not already there
local loadingScreenScript = ReplicatedStorage.LoadingScreenScript
if not loadingScreenScript:IsDescendantOf(ReplicatedFirst) then
loadingScreenScript.Parent = ReplicatedFirst
end
-- Move atmosphere, sky, and bloom objects to Lighting based on the selected map
if mapToLoad == junkyardMap then
ReplicatedStorage.JunkyardAtmosphere.Parent = Lighting
ReplicatedStorage.JunkyardSky.Parent = Lighting
ReplicatedStorage.JunkyardBloom.Parent = Lighting
elseif mapToLoad == warehouseMap then
ReplicatedStorage.WarehouseAtmosphere.Parent = Lighting
ReplicatedStorage.WarehouseSky.Parent = Lighting
ReplicatedStorage.WarehouseBloom.Parent = Lighting
end
-- Teleport players to the map
if mapToLoad == junkyardMap then
local spawnPoints = {
CFrame.new(330.5, 7, 139.5),
CFrame.new(49.5,7, 122.5),
CFrame.new(-50.5, 7, 490.5)
}
for _, player in ipairs(game:GetService("Players"):GetPlayers()) do
player.Character:SetPrimaryPartCFrame(spawnPoints[math.random(#spawnPoints)])
end
elseif mapToLoad == warehouseMap then
local spawnPoints = {
CFrame.new(-571.5, 7, -21.5),
CFrame.new(-628.5, 7, -379.5),
CFrame.new(-813.5, 7, -503.5)
}
for _, player in ipairs(game:GetService("Players"):GetPlayers()) do
player.Character:SetPrimaryPartCFrame(spawnPoints[math.random(#spawnPoints)])
end
end
-- Makes the camera not blurry if it's currently blurry
local blur = Instance.new("BlurEffect")
blur.Parent = game:GetService("Lighting")
blur.Size = 20
for i = 20, 0, -1 do
blur.Size = i
task.wait(0.2)
end
blur:Destroy()
-- Let the players play in the map for 3 minutes before the round ends (I have it set to 26 seconds currently for testing)
wait(26)
-- Makes the camera blurry
local blur = Instance.new("BlurEffect")
blur.Parent = game:GetService("Lighting")
blur.Size = 0
for i = 1, 20 do
blur.Size = i
task.wait(0.2)
end
-- Move maps back to ReplicatedStorage
mapToLoad.Parent = ReplicatedStorage.Maps
-- Move monsters back to ReplicatedStorage
for i = 1, 6 do
local monster = Workspace:FindFirstChild("Monster" .. i)
if monster then
monster.Parent = ReplicatedStorage
end
end
-- Move lighting to ReplicatedStorage
if mapToLoad == junkyardMap then
ReplicatedStorage.JunkyardAtmosphere.Parent = maps
ReplicatedStorage.JunkyardSky.Parent = maps
ReplicatedStorage.JunkyardBloom.Parent = maps
elseif mapToLoad == warehouseMap then
ReplicatedStorage.WarehouseAtmosphere.Parent = maps
ReplicatedStorage.WarehouseSky.Parent = maps
ReplicatedStorage.WarehouseBloom.Parent = maps
end
wait(1)
end