So my script when ran always says something along the lines of this - "MainScript timed out before resuming thread". If anyone knows any tricks to fix this please do answer. By the way, my while true loops do have waits at the end of them so that is not the problem.
--Made by iiMeltex local roundtime = 60 * 3 local finaletime = 1* 60 local intermissiontime = 15 local serverstorage = game:GetService("ServerStorage") local replicatedstorage = game:GetService("ReplicatedStorage") local debris = game:GetService("Debris") local maps = serverstorage:WaitForChild("Maps") local mapholder = game.Workspace:WaitForChild("Mapholder") local event = replicatedstorage:WaitForChild("RemoteEvent") local statustag = replicatedstorage:WaitForChild("StatusTag") local timertag = replicatedstorage:WaitForChild("TimerTag") function awardpoints(player, points) if player and points then local leaderstats = player.FindFirstChild("leaderstats") if leaderstats then local pointsvalue = leaderstats:FindFirstChild("Points") if pointsvalue then pointsvalue.Value = pointsvalue.Value + points end end end end function newcharacter(deadplayer, character) local humanoid = character:FindFirstChild("Humanoid") if humanoid then humanoid.Died:connect(function() humanoid.WalkSpeed = 16 humanoid.UnequipTools() local backpack = deadplayer:FindFirstChild("Backpack") if backpack then backpack:ClearAllChildren() end local tag = humanoid:FindFirstChild("creator") if tag and tag.Value and tag.Value.Parent == game.Players then if tag.Value == hunter and deadplayer == hunter then local wrongdoer = tag.Value if wrongdoer.Character and wrongdoer.Character.Parent then local wrongdoerhumanoid = wrongdoer.Character:FindFirstChild("Humanoid") if wrongdoerhumanoid then wrongdoerhumanoid.Health = 0 end end end end end) end end function playeradded(player) local leaderstats = Instance.new("Model") leaderstats.Name = "leaderstats" leaderstats.Parent = player local wins = Instance.new("IntValue") wins.Name = "Wins" wins.Parent = leaderstats local points = Instance.new("IntValue") points.Name = "Points" points.Parent = leaderstats player.CharacterAdded:connect(function(character) newcharacter(player, character) end) if player.Character and player.Character.Parent then newcharacter(player, player.character) end end game.Players.PlayerAdded:connect(playeradded) for _, player in pairs(game.Players:GetPlayers()) do playeradded(player) end while true do while true do wait(4) contestants = {} for _,player in pairs(game.Players:GetPlayers()) do if player and player.Character then local humanoid = player.Character:WaitForChild("Humanoid") if humanoid and humanoid.Health > 0 then table.insert(contestants, player) end end end if #contestants >= 3 then break else statustag.Value = "Waiting For More Players" timertag.Value = -1 end end --load a random map statustag.Value = "Loading A Random Map" timertag.Value = -1 mapholder:ClearAllChildren() wait(2) local allmaps = maps:GetChildren() local newmap = allmaps[math.random(1, #allmaps)]:clone() newmap.Parent = game.Workspace.Mapholder wait(2) statustag.Value = "Match" timertag.Value = roundtime --choose hunter hunter = contestants[math.random(1, #contestants)] --blur --teleport all contestants local spawnsmodel = newmap:WaitForChild("Spawns") local spawns = spawnsmodel:GetChildren() for _,player in pairs(contestants) do if player and player.Character and #spawns > 0 then local torso = player.Character:WaitForChild("Torso") local humanoid = player.Character:WaitForChild("Humanoid") local spawnindex = math.random(1, #spawns) local spawn = spawns[spawnindex] if spawn and torso and humanoid then humanoid.Health = 100 humanoid.WalkSpeed = 16 table.remove(spawns, spawnindex) torso.CFrame = CFrame.new(spawn.Position + Vector3.new(0, 3, 0)) local matchtag = Instance.new("StringValue") matchtag.Name = "Matchtag" matchtag.Parent = player.Character local backpack = player.FindFirstChild("Backpack") if backpack then if player == hunter then local sword = serverstorage:WaitForChild("Bamboo Katana"):clone() sword.Parent = backpack local humanoid = player.Character.Humanoid humanoid.WalkSpeed = 18 event:FireClient(player, "Class", "Hunter") else local flashlight = serverstorage:WaitForChild("Flashlight"):clone() flashlight.Parent = backpack event:FireClient(player, "Class", "Hunted") end end end end end spawnsmodel:remove() --focus local localtimer = roundtime while localtimer > 0 do wait(1) localtimer = localtimer - 1 timertag.Value = localtimer activecontestants = {} hunteractive = false for _,player in pairs(contestants) do if player then local character = player.Character if character then local matchtag = character:FindFirstChild("Matchtag") local humanoid = character:FindFirstChild("Humanoid") if matchtag and humanoid and humanoid.Health > 0 then if player == hunter then hunteractive = true end table.insert(activecontestants, player) end end end end if #activecontestants <= 1 or not hunteractive then break end end for _,player in pairs(activecontestants) do local character = player.Character local matchtag = character:FindFirstChild("Matchtag") local humanoid = character:FindFirstChild("Humanoid") if player and matchtag and humanoid and humanoid.Health > 0 then local backpack = player.FindFirstChild("Backpack") local pistol = serverstorage:WaitForChild("Pistol"):clone() pistol.Parent = backpack end end statustag.Value = "Finale" timertag.Value = finaletime local localtimer = finaletime while localtimer > 0 do if #activecontestants <= 1 or not hunteractive then break end wait(1) localtimer = localtimer - 1 timertag.Value = localtimer activecontestants = {} hunteractive = false for _,player in pairs(contestants) do if player then local character = player.Character if character then local matchtag = character:FindFirstChild("Matchtag") local humanoid = character:FindFirstChild("Humanoid") if matchtag and humanoid and humanoid.Health > 0 then if player == hunter then hunteractive = true end table.insert(activecontestants, player) end end end end end local gameresults = "PlayersWin" if hunteractive then if #activecontestants >= 2 then event:FireAllClients("Results", "HuntedWin") else gameresults = "HunterWin" event:FireAllClients("Results", "HunterWin") end else event:FireAllClients("Results", "HuntedWin") end for _,player in pairs(activecontestants) do if player then if gameresults == "HunterWin" and player == hunter then awardpoints(player, 10) elseif gameresults ~= "HunterWin" and player ~= hunter then awardpoints(player, 4) end end end local lobbyspawns = {} for _, v in pairs(game.Workspace:WaitForChild("Lobby"):WaitForChild("SpawnPoints"):GetAllChildren()) do if v and v.Name == "SpawnLocation" then table.insert(lobbyspawns, v) end end for _,player in pairs(activecontestants) do if player then awardpoints(player, 1) if player.Character then local humanoid = player.Character:FindFirstChild("Humannoid") if humanoid and humanoid.Health > 0 then humanoid:UnequipTools() end end local randomspawn = lobbyspawns[math.random(1, #lobbyspawns)] player.Character:MoveTo(randomspawn.Position) local backpack = player:FindFirstChlid("Backpack") if backpack then backpack:ClearAllChildren() end end end statustag.Value = "Intermission" timertag.Value = intermissiontime local localtimer = intermissiontime while localtimer > 0 do wait(1) localtimer = localtimer - 1 timertag.Value = localtimer end wait(0.01) end