Advertisement
HowToRoblox

SquidGameServer

Dec 19th, 2021
1,563
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.17 KB | None | 0 0
  1. local gameLength = 120
  2.  
  3.  
  4. game.Players.PlayerAdded:Connect(function(plr)
  5.    
  6.    
  7.     local ls = Instance.new("Folder", plr)
  8.     ls.Name = "leaderstats"
  9.    
  10.     local cash = Instance.new("IntValue", ls)
  11.     cash.Name = "Cash"
  12. end)
  13.  
  14.  
  15. local playersAlive = {}
  16. local playersCompleted = {}
  17.  
  18. local redLight = false
  19. local cookieGame = false
  20.  
  21.  
  22. local playerCookieCracks = {}
  23. local playerMouses = {}
  24.  
  25. game.ReplicatedStorage.SquidGameRE.OnServerEvent:Connect(function(player, mouseStatus, mouseCF)
  26.  
  27.     if mouseStatus then
  28.  
  29.         playerMouses[player] = mouseCF
  30.  
  31.     else
  32.         playerMouses[player] = nil
  33.     end
  34. end)
  35.  
  36.  
  37. game:GetService("RunService").Heartbeat:Connect(function()
  38.    
  39.     for i, player in pairs(game.Players:GetPlayers()) do
  40.  
  41.         if player.Character and player.Character:FindFirstChild("Humanoid") then
  42.  
  43.             if player.Character.HumanoidRootPart.Velocity.Magnitude > 0 and redLight and table.find(playersAlive, player) then
  44.                
  45.                 player.Character.Humanoid.Health = 0
  46.                
  47.                 script.Shot:Play()
  48.                
  49.                
  50.             elseif cookieGame then
  51.                
  52.                 if playerMouses[player] and script.Parent.Honeycomb.Cookies:FindFirstChild(player.Name .. "Cookie") then
  53.                    
  54.                     local cookie = script.Parent.Honeycomb.Cookies[player.Name .. "Cookie"]
  55.                    
  56.                     local nextPiece = nil
  57.                    
  58.                     for i = 1, #cookie.Shape:GetChildren() do
  59.                        
  60.                         if cookie.Shape[i].Color == Color3.fromRGB(27, 42, 53) then
  61.                            
  62.                             nextPiece = cookie.Shape[i]
  63.                            
  64.                             break
  65.                         end
  66.                     end
  67.                    
  68.                     if nextPiece and playerMouses[player] == nextPiece then
  69.                        
  70.                         nextPiece.Color = Color3.fromRGB(62, 223, 17)
  71.                        
  72.                        
  73.                     elseif playerMouses[player].Parent ~= script.Parent.Honeycomb.Cookies[player.Name .. "Cookie"].Shape and not playerCookieCracks[player] then
  74.                        
  75.                         playerCookieCracks[player] = true
  76.                        
  77.                         game.ReplicatedStorage.HoneycombCrackDecal:Clone().Parent = script.Parent.Honeycomb.Cookies[player.Name .. "Cookie"].Cookie
  78.                        
  79.                         script.Crack:Play()
  80.                        
  81.                         wait(3)
  82.                         playerCookieCracks[player] = false
  83.                        
  84.                        
  85.                     elseif not nextPiece then
  86.                        
  87.                         table.remove(playersAlive, table.find(playersAlive, player))
  88.                         table.insert(playersCompleted, player)
  89.                        
  90.                         script.Parent.Honeycomb.Cookies[player.Name .. "Cookie"]:Destroy()
  91.                        
  92.                         player.Character.HumanoidRootPart.Anchored = false
  93.                     end
  94.                 end
  95.             end
  96.         end
  97.     end
  98. end)
  99.  
  100.  
  101.  
  102. while true do
  103.    
  104.     wait(3)
  105.    
  106.    
  107.     playersAlive = {}
  108.     playersCompleted = {}
  109.    
  110.     script.Parent.Honeycomb.PlayerCells:ClearAllChildren()
  111.    
  112.     script.Parent.RedLightGreenLight.PreGameBarrier.CanCollide = true
  113.     script.Parent.RedLightGreenLight.EndGameBarrier.CanCollide = false
  114.    
  115.     script.Parent.RedLightGreenLight.Doll.Head.Orientation = Vector3.new(0, 0, 0)
  116.    
  117.    
  118.     for i, player in pairs(game.Players:GetPlayers()) do
  119.        
  120.         player:LoadCharacter()
  121.        
  122.        
  123.         player.Character.HumanoidRootPart.CFrame = script.Parent.RedLightGreenLight.SpawnPart.CFrame
  124.        
  125.            
  126.         table.insert(playersAlive, player)
  127.        
  128.        
  129.         player.Character.Humanoid.Died:Connect(function()
  130.            
  131.             table.remove(playersAlive, table.find(playersAlive, player))
  132.         end)
  133.     end
  134.    
  135.    
  136.     game.ReplicatedStorage.SquidGameRE:FireAllClients("status", "Game starting..", Color3.fromRGB(255, 255, 255))
  137.    
  138.    
  139.     wait(3)
  140.    
  141.    
  142.     --Red Light Green Light Game
  143.    
  144.     script.Parent.RedLightGreenLight.PreGameBarrier.CanCollide = false
  145.    
  146.    
  147.     local timeLeft = gameLength
  148.    
  149.    
  150.     spawn(function()
  151.        
  152.         while timeLeft > 0 and #playersAlive > 0 do
  153.            
  154.             timeLeft -= 1
  155.            
  156.             local mins = math.floor(timeLeft / 60)
  157.             local secs = timeLeft % 60
  158.            
  159.             if string.len(mins) < 2 then mins = "0" .. mins end
  160.             if string.len(secs) < 2 then secs = "0" .. secs end
  161.            
  162.             game.ReplicatedStorage.SquidGameRE:FireAllClients("timer", mins .. ":" .. secs)
  163.            
  164.             wait(1)
  165.         end
  166.     end)
  167.    
  168.    
  169.     script.Parent.RedLightGreenLight.EndGameBarrier.Touched:Connect(function(hit)
  170.        
  171.         local player = game.Players:GetPlayerFromCharacter(hit.Parent)
  172.        
  173.         if table.find(playersAlive, player) then
  174.            
  175.             table.remove(playersAlive, table.find(playersAlive, player))
  176.            
  177.             table.insert(playersCompleted, player)
  178.            
  179.             game.ReplicatedStorage.SquidGameRE:FireClient(player, "barrier", script.Parent.RedLightGreenLight.EndGameBarrier)
  180.         end
  181.     end)
  182.    
  183.    
  184.     while timeLeft > 0 and #playersAlive > 0 do
  185.        
  186.        
  187.         game.ReplicatedStorage.SquidGameRE:FireAllClients("status", "GREEN LIGHT", Color3.fromRGB(0, 255, 0))
  188.        
  189.        
  190.         local randomSpeed = math.random(8, 13)/10
  191.         script.Song.PlaybackSpeed = randomSpeed
  192.        
  193.        
  194.         script.Song:Play()
  195.        
  196.         script.Song.Ended:Wait()
  197.        
  198.        
  199.         game:GetService("TweenService"):Create(script.Parent.RedLightGreenLight.Doll.Head, TweenInfo.new(0.3), {Orientation = Vector3.new(0, 180, 0)}):Play()
  200.         redLight = true
  201.        
  202.         game.ReplicatedStorage.SquidGameRE:FireAllClients("status", "RED LIGHT", Color3.fromRGB(255, 0, 0))
  203.        
  204.         wait(math.random(1, 5))
  205.        
  206.         game:GetService("TweenService"):Create(script.Parent.RedLightGreenLight.Doll.Head, TweenInfo.new(0.3), {Orientation = Vector3.new(0, 0, 0)}):Play()
  207.         redLight = false
  208.     end
  209.    
  210.    
  211.     for i, player in pairs(playersAlive) do
  212.        
  213.         player.Character.Humanoid.Health = 0
  214.        
  215.         script.Shot:Play()
  216.     end
  217.    
  218.    
  219.     wait(5)
  220.    
  221.    
  222.     --Honeycomb Game
  223.    
  224.     playersAlive = playersCompleted
  225.     playersCompleted = {}
  226.    
  227.    
  228.     game.ReplicatedStorage.SquidGameRE:FireAllClients("status", "CUT THE COOKIE", Color3.fromRGB(255, 255, 255))
  229.    
  230.    
  231.     for i, spawnPart in pairs(script.Parent.Honeycomb.Spawns:GetChildren()) do
  232.        
  233.         local player = playersAlive[i]
  234.        
  235.         if player then
  236.            
  237.             local newBlock = game.ReplicatedStorage.HoneycombTemplate:Clone()
  238.            
  239.             newBlock:SetPrimaryPartCFrame(spawnPart.CFrame)
  240.            
  241.            
  242.             newBlock.Parent = script.Parent.Honeycomb.PlayerCells
  243.            
  244.             player.Character.HumanoidRootPart.CFrame = newBlock.SpawnPart.CFrame
  245.             wait()
  246.             player.Character.HumanoidRootPart.Anchored = true
  247.            
  248.            
  249.             local cookie = game.ReplicatedStorage.HoneycombCookies:GetChildren()[math.random(1, #game.ReplicatedStorage.HoneycombCookies:GetChildren())]:Clone()
  250.             cookie.Name = player.Name .. "Cookie"
  251.             cookie.Parent = script.Parent.Honeycomb.Cookies
  252.             cookie.Shape["1"].Color = Color3.fromRGB(62, 223, 17)
  253.            
  254.             game.ReplicatedStorage.SquidGameRE:FireClient(player, "honeycomb", cookie)
  255.            
  256.            
  257.             cookie.Cookie.ChildAdded:Connect(function()
  258.                
  259.                 if #cookie.Cookie:GetChildren() > 2 then
  260.                    
  261.                     player.Character.Humanoid.Health = 0
  262.                     script.Shot:Play()
  263.                 end
  264.             end)
  265.         end
  266.     end
  267.    
  268.    
  269.    
  270.     timeLeft = gameLength
  271.    
  272.    
  273.     cookieGame = true
  274.  
  275.     while timeLeft > 0 and #playersAlive > 0 do
  276.  
  277.         timeLeft -= 1
  278.  
  279.         local mins = math.floor(timeLeft / 60)
  280.         local secs = timeLeft % 60
  281.  
  282.         if string.len(mins) < 2 then mins = "0" .. mins end
  283.         if string.len(secs) < 2 then secs = "0" .. secs end
  284.        
  285.         game.ReplicatedStorage.SquidGameRE:FireAllClients("timer", mins .. ":" .. secs)
  286.  
  287.         wait(1)
  288.     end
  289.    
  290.    
  291.     script.Parent.Honeycomb.Cookies:ClearAllChildren()
  292.    
  293.    
  294.     for i, player in pairs(playersAlive) do
  295.  
  296.         player.Character.Humanoid.Health = 0
  297.  
  298.         script.Shot:Play()
  299.     end
  300.    
  301.    
  302.     game.ReplicatedStorage.SquidGameRE:FireAllClients("honeycombEnd")
  303.     cookieGame = false
  304.    
  305.    
  306.     --Glass Tiles Game
  307.    
  308.     playersAlive = playersCompleted
  309.     playersCompleted = {}
  310.  
  311.  
  312.     game.ReplicatedStorage.SquidGameRE:FireAllClients("status", "GLASS TILES", Color3.fromRGB(255, 255, 255))
  313.  
  314.  
  315.     for i, player in pairs(playersAlive) do
  316.  
  317.         player.Character.HumanoidRootPart.CFrame = script.Parent.GlassTiles.SpawnPart.CFrame
  318.     end
  319.    
  320.     for tileNum = 1, #script.Parent.GlassTiles.TilesLeft:GetChildren() do
  321.        
  322.         script.Parent.GlassTiles.TilesLeft[tileNum].Transparency, script.Parent.GlassTiles.TilesRight[tileNum].Transparency = 0.4, 0.4
  323.        
  324.         local num = math.random(0, 1)
  325.        
  326.         local tile = num == 0 and script.Parent.GlassTiles.TilesLeft[tileNum] or script.Parent.GlassTiles.TilesRight[tileNum]
  327.         tile.CanCollide = false
  328.        
  329.         tile.Touched:Connect(function()
  330.             tile.Transparency = 1
  331.         end)
  332.     end
  333.    
  334.     script.Parent.GlassTiles.Floor.Touched:Connect(function(hit)
  335.        
  336.         local player = game.Players:GetPlayerFromCharacter(hit.Parent)
  337.  
  338.         if player then
  339.            
  340.             hit.Parent.Humanoid.Health = 0
  341.         end
  342.     end)
  343.    
  344.     script.Parent.GlassTiles.End.Touched:Connect(function(hit)
  345.        
  346.         local player = game.Players:GetPlayerFromCharacter(hit.Parent)
  347.  
  348.         if table.find(playersAlive, player) then
  349.  
  350.             table.remove(playersAlive, table.find(playersAlive, player))
  351.  
  352.             table.insert(playersCompleted, player)
  353.            
  354.             wait(1)
  355.            
  356.             hit.Parent.HumanoidRootPart.Anchored = true
  357.         end
  358.     end)
  359.    
  360.    
  361.     timeLeft = gameLength
  362.    
  363.    
  364.     while timeLeft > 0 and #playersAlive > 0 do
  365.  
  366.         timeLeft -= 1
  367.  
  368.         local mins = math.floor(timeLeft / 60)
  369.         local secs = timeLeft % 60
  370.  
  371.         if string.len(mins) < 2 then mins = "0" .. mins end
  372.         if string.len(secs) < 2 then secs = "0" .. secs end
  373.  
  374.         game.ReplicatedStorage.SquidGameRE:FireAllClients("timer", mins .. ":" .. secs)
  375.  
  376.         wait(1)
  377.     end
  378.    
  379.    
  380.     for i, player in pairs(playersAlive) do
  381.  
  382.         player.Character.Humanoid.Health = 0
  383.  
  384.         script.Shot:Play()
  385.     end
  386.    
  387.    
  388.    
  389.     --Reward winners
  390.    
  391.     for i, player in pairs(playersCompleted) do
  392.        
  393.         player.leaderstats.Cash.Value += math.floor(10000 / #playersCompleted)
  394.     end
  395. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement