Advertisement
StefanBashkir

Connor's Game Script V1.3

Dec 12th, 2013
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.16 KB | None | 0 0
  1. script.Name = "serverCode"
  2. -- PUT ALL YOUR MAPS in game.Lighting.maps
  3. -- MAKE A MODEL IN LIGHTING CALLED maps AND PUT ALL THE MAPS THERE
  4. --====================================================================================--
  5. --========================================Game Settings============================================--
  6. --====================================================================================--
  7. local countdownTime             = 10; -- seconds for countdown
  8. local timeBetweenRounds         = 10; -- seconds between rounds
  9. local hoverboardGamePasses = {
  10.     ['938736673']   = "GearNameInLighting"; -- The first number is the gamepassId and the second is the name of gear in the lighting they get
  11.     ['387436634']   = "AnotherGearName";
  12. }
  13. local swordGamePasses = {
  14.     ['938736673']   = "GearNameInLighting";
  15.     ['387436634']   = "AnotherGearName";
  16. }
  17. --====================================================================================--
  18. --====================================================================================--
  19. --====================================================================================--
  20.  
  21. local spectator         = Game.Lighting:WaitForChild([==[Spectate]==]); -- name of spectator tool/hopperbin
  22. local shopGui           = Game.Lighting:WaitForChild([==[Shop]==]); -- Name of shopGui is Shop
  23. local mapDirectory      = game.Lighting:FindFirstChild("maps"); mapDirectory = mapDirectory:GetChildren()
  24. local map;
  25. local lobby             = Workspace.Lobby
  26. local Create            = assert(LoadLibrary("RbxUtility")).Create
  27.  
  28. local timer             = script:FindFirstChild("timer") and script.timer or Create("IntValue"){
  29.     Name = "timer",
  30.     Parent = script
  31. }
  32.  
  33. local function updateMap()
  34.     local newMap = mapDirectory[math.random(1, #mapDirectory)]
  35.     newMap:Clone().Parent = workspace
  36.     map = workspace:WaitForChild("map")
  37.     wait(0.5)
  38. end
  39.  
  40. local function giveSpectate()
  41.     for i,v in pairs(Game.Players:GetPlayers()) do
  42.         if not v.Backpack:FindFirstChild(spectator.Name) then
  43.             spectator:Clone().Parent = v.Backpack
  44.         end
  45.     end
  46. end
  47.  
  48. local function giveSpectateTo(pl)
  49.     if not pl.Backpack:FindFirstChild(spectator.Name) then
  50.         spectator:Clone().Parent = pl.Backpack
  51.     end
  52. end
  53.  
  54. local function removeSpectate()
  55.     for i,v in pairs(Game.Players:GetPlayers()) do
  56.         if v.Backpack:FindFirstChild(spectator.Name) then
  57.             v.Backpack[spectator.Name]:Destroy();
  58.         end
  59.     end
  60. end
  61.  
  62. local function ToggleShopGui(bool, pl)
  63.     if bool then
  64.         shopGui:Clone().Parent = pl:WaitForChild("PlayerGui");
  65.     else
  66.         pcall(function()
  67.             pl.PlayerGui.Shop:Destroy();
  68.         end)
  69.     end
  70. end
  71.  
  72. local function teleportToMap()
  73.     teleportTo = { }
  74.     for _, object in pairs(map:GetChildren()) do
  75.         if object.Name == "teleportTo" then
  76.             table.insert(teleportTo, object.Position)
  77.         end
  78.     end
  79.     for _, player in pairs(game.Players:GetPlayers()) do
  80.         if workspace:FindFirstChild(player.Name) and player:FindFirstChild("isInMap") then
  81.             player.Character:MoveTo(teleportTo[math.random(1, #teleportTo)] + Vector3.new(0, 5, 0))
  82.             player.isInMap.Value = true
  83.         end
  84.     end
  85. end
  86.  
  87.  
  88. local function give(name)
  89.     for _, player in pairs(game.Players:GetPlayers()) do
  90.         if player:FindFirstChild(name) then
  91.             if game.Lighting:FindFirstChild(player[name].Value) then
  92.                 game.Lighting[player[name].Value]:Clone().Parent = player.Backpack
  93.                 if name == "board" then
  94.                     for i,v in pairs(player.BoughtItems.Hoverboards:GetChildren()) do
  95.                         v:Clone().Parent = player.Backpack
  96.                     end
  97.                 elseif name == "sword" then
  98.                     for i,v in pairs(player.BoughtItems.Swords:GetChildren()) do
  99.                         v:Clone().Parent = player.Backpack
  100.                     end
  101.                 end
  102.             end
  103.         end
  104.     end
  105.     if name == "board" then
  106.         for i,v in pairs(game.Players:GetPlayers()) do
  107.             local s = Game:GetService([==[GamePassService]==]);
  108.             for k,j in pairs(hoverboardGamePasses) do
  109.                 if s:PlayerHasPass(v.userId, tonumber(k)) then
  110.                     Game.Lighting[j]:Clone().Parent = v.Backpack
  111.                 end
  112.             end
  113.         end
  114.     elseif name == "sword" then
  115.         for i,v in pairs(game.Players:GetPlayers()) do
  116.             local s = Game:GetService([==[GamePassService]==]);
  117.             for k,j in pairs(swordGamePasses) do
  118.                 if s:PlayerHasPass(v.userId, tonumber(k)) then
  119.                     Game.Lighting[j]:Clone().Parent = v.Backpack
  120.                 end
  121.             end
  122.         end
  123.     end
  124. end
  125.  
  126. local function countDown()
  127.     local door = map:FindFirstChild("door")
  128.     door.CanCollide = true
  129.     door.Transparency = 0.5
  130.     for i = countdownTime, 1, -1 do
  131.         timer.Value = i
  132.         wait(1)
  133.     end
  134.     for i = 0.5, 1, 0.1 do
  135.         door.Transparency = i
  136.         wait(0.03)
  137.     end
  138.     door.CanCollide = false
  139. end
  140.  
  141. local function waitForWinner()
  142.     local door = map:FindFirstChild("door")
  143.     local alreadyWon = false
  144.     local lastWinner = nil;
  145.     door.Touched:connect(function(part)
  146.         local humanoid = part.Parent:FindFirstChild("Humanoid") or part.Parent.Parent:FindFirstChild("Humanoid")
  147.         if humanoid and not alreadyWon then
  148.             local player = game.Players:GetPlayerFromCharacter(humanoid.Parent)
  149.             if player:FindFirstChild("wonRound") then
  150.                 player.wonRound.Value = not player.wonRound.Value
  151.                 alreadyWon = true
  152.                 lastWinner = player
  153.             end
  154.         end
  155.     end)
  156.     repeat wait(0.5) until alreadyWon
  157.     return lastWinner;
  158. end
  159.  
  160. local function teleportToLobby(lastWinner)
  161.     local teleportTo = { }
  162.     for _, object in pairs(lobby:GetChildren()) do
  163.          if object.Name == "teleportTo" then
  164.             table.insert(teleportTo, object.Position)
  165.         end
  166.     end
  167.     lobby.Leader.Decal.Texture = "http://www.roblox.com/Thumbs/Avatar.ashx?x=100&y=100&Format=Png&username=" .. lastWinner.Name;
  168.     for _, player in pairs(game.Players:GetPlayers()) do
  169.         if player:FindFirstChild("isInMap") then
  170.             if player.isInMap.Value then
  171.                 player.Character:MoveTo(teleportTo[math.random(1, #teleportTo)] + Vector3.new(0, 5, 0))
  172.                 player.isInMap.Value = false
  173.             end
  174.         end
  175.     end
  176. end
  177.  
  178. local function startRound()
  179.     updateMap()
  180.     removeSpectate();
  181.     teleportToMap()
  182.     for i,v in pairs(Game.Players:GetPlayers()) do
  183.         ToggleShopGui(false,v);
  184.     end
  185.     give("board")
  186.     countDown()
  187.     wait(10)
  188.     give("sword")
  189.     teleportToLobby(waitForWinner())
  190.     for i,v in pairs(Game.Players:GetPlayers()) do
  191.         ToggleShopGui(true,v);
  192.     end
  193. end
  194.  
  195. local function intermission()
  196.     repeat wait(1) until game.Players.NumPlayers > 1
  197.     for i = timeBetweenRounds, 1, -1 do
  198.         timer.Value = i
  199.         wait(1)
  200.         if not game.Players.NumPlayers > 1 then
  201.             return false
  202.         end
  203.     end
  204.     return true
  205. end
  206.  
  207. game.Players.PlayerAdded:connect(function(player)
  208.     Create("StringValue"){
  209.         Name = "board",
  210.         Parent = player
  211.     }
  212.     Create("StringValue"){
  213.         Name = "sword",
  214.         Parent = player
  215.     }
  216.     Create("BoolValue"){
  217.         Name = "isInMap",
  218.         Parent = player
  219.     }
  220.     Create("BoolValue"){
  221.         Name = "wonRound",
  222.         Parent = player
  223.     }
  224.     Create("BoolValue"){
  225.         Name = "hasGamePass",
  226.         Parent = player
  227.     }
  228.     Create("IntValue"){
  229.         Name = "leaderboard",
  230.         Parent = player
  231.     }
  232.     Create("IntValue"){
  233.         Name = "Points",
  234.         Parent = player:WaitForChild("leaderboard")
  235.     }
  236.     Create("IntValue"){
  237.         Name = "Kills",
  238.         Parent = player:WaitForChild("leaderboard")
  239.     }
  240.     Create("Model"){
  241.         Name = "BoughtItems",
  242.         Parent = player
  243.     }
  244.     Create("Model"){
  245.         Name = "Hoverboards",
  246.         Parent = player:WaitForChild("BoughtItems");
  247.     }
  248.     Create("Model"){
  249.         Name = "Swords",
  250.         Parent = player:WaitForChild([===================[BoughtItems]===================]);
  251.     }
  252.     player:WaitForChild("Kills").Changed:connect(function()
  253.         local points = player:WaitForChild("Points")
  254.         local earnedPoints = player:WaitForChild("hasGamePass").Value and 100 or 50
  255.         points.Value = points.Value + earnedPoints
  256.     end)
  257.     player:WaitForChild("wonRound").Changed:connect(function()
  258.         local points = player:WaitForChild("Points")
  259.         local earnedPoints = player:WaitForChild("hasGamePass").Value and 500 or 200
  260.         points.Value = points.Value + earnedPoints
  261.     end)
  262.     player.CharacterAdded:connect(function(character)
  263.         if not player.isInMap.Value then
  264.             giveSpectateTo(player);
  265.         end
  266.         workspace:WaitForChild(player.Name)
  267.         character:WaitForChild("Humanoid").Died:connect(function()
  268.             player.isInMap.Value = false
  269.         end)
  270.     end)
  271. end)
  272.  
  273. while true do
  274.     local interrupted = intermission()
  275.     if not interrupted then
  276.         startRound()
  277.     end
  278. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement