Advertisement
HowToRoblox

GameServer

Aug 29th, 2021
2,350
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.62 KB | None | 0 0
  1. local re = game.ReplicatedStorage:WaitForChild("RemoteEvent")
  2.  
  3. local maps = game.ReplicatedStorage:WaitForChild("Maps"):GetChildren()
  4.  
  5.  
  6. local gameLength = 120
  7.  
  8.  
  9.  
  10. while true do
  11.    
  12.    
  13.     local chosenMap = maps[math.random(1, #maps)]:Clone()
  14.     chosenMap.Parent = workspace
  15.    
  16.     re:FireAllClients("status", "Map chosen: " .. chosenMap.Name)
  17.    
  18.    
  19.     for i, plr in pairs(game.Players:GetPlayers()) do
  20.        
  21.         plr:LoadCharacter()
  22.     end
  23.    
  24.    
  25.     wait(3)
  26.    
  27.    
  28.     local speedMultiplier = 1
  29.    
  30.     local plrsCompleted = {}
  31.    
  32.     chosenMap.Finish.Touched:Connect(function(hit)
  33.        
  34.         local player = game.Players:GetPlayerFromCharacter(hit.Parent)
  35.        
  36.         if player and not table.find(plrsCompleted, player) then
  37.            
  38.             table.insert(plrsCompleted, player)
  39.  
  40.             re:FireAllClients("chat", player.Name .. " has made it to the end.")
  41.            
  42.             re:FireClient(player, "finished", chosenMap.Finish)
  43.            
  44.             player.leaderstats.Money.Value += 300 / speedMultiplier
  45.            
  46.             speedMultiplier *= 2
  47.         end
  48.     end)
  49.    
  50.    
  51.     for i, killPart in pairs(chosenMap.KillParts:GetChildren()) do
  52.        
  53.         killPart.Touched:Connect(function(hit)
  54.            
  55.             local player = game.Players:GetPlayerFromCharacter(hit.Parent)
  56.            
  57.             if player then
  58.                
  59.                 player:LoadCharacter()
  60.             end
  61.         end)
  62.     end
  63.    
  64.    
  65.     for i = gameLength, 0, -1 do
  66.        
  67.         wait(1 / speedMultiplier)
  68.        
  69.         local timeMins = math.floor(i / 60)
  70.         local timeSecs = i % 60
  71.        
  72.         if string.len(timeSecs) < 2 then timeSecs = "0" .. timeSecs end
  73.        
  74.         re:FireAllClients("status", timeMins .. ":" .. timeSecs)
  75.        
  76.        
  77.         if #plrsCompleted == #game.Players:GetPlayers() then
  78.            
  79.             break
  80.         end
  81.     end
  82.    
  83.     chosenMap:Destroy()
  84. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement