HowToRoblox

SquidGameServer

Oct 27th, 2021
1,066
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.    
  145.     script.Parent.RedLightGreenLight.PreGameBarrier.CanCollide = false
  146.    
  147.    
  148.     local timeLeft = gameLength
  149.    
  150.    
  151.     spawn(function()
  152.        
  153.         while timeLeft > 0 and #playersAlive > 0 do
  154.            
  155.             timeLeft -= 1
  156.            
  157.             local mins = math.floor(timeLeft / 60)
  158.             local secs = timeLeft % 60
  159.            
  160.             if string.len(mins) < 2 then mins = "0" .. mins end
  161.             if string.len(secs) < 2 then secs = "0" .. secs end
  162.            
  163.             game.ReplicatedStorage.SquidGameRE:FireAllClients("timer", mins .. ":" .. secs)
  164.            
  165.             wait(1)
  166.         end
  167.     end)
  168.    
  169.    
  170.     script.Parent.RedLightGreenLight.EndGameBarrier.Touched:Connect(function(hit)
  171.        
  172.         local player = game.Players:GetPlayerFromCharacter(hit.Parent)
  173.        
  174.         if table.find(playersAlive, player) then
  175.            
  176.             table.remove(playersAlive, table.find(playersAlive, player))
  177.            
  178.             table.insert(playersCompleted, player)
  179.            
  180.             game.ReplicatedStorage.SquidGameRE:FireClient(player, "barrier", script.Parent.RedLightGreenLight.EndGameBarrier)
  181.         end
  182.     end)
  183.    
  184.    
  185.     while timeLeft > 0 and #playersAlive > 0 do
  186.        
  187.        
  188.         game.ReplicatedStorage.SquidGameRE:FireAllClients("status", "GREEN LIGHT", Color3.fromRGB(0, 255, 0))
  189.        
  190.        
  191.         local randomSpeed = math.random(8, 13)/10
  192.         script.Song.PlaybackSpeed = randomSpeed
  193.        
  194.        
  195.         script.Song:Play()
  196.        
  197.         script.Song.Ended:Wait()
  198.        
  199.        
  200.         game:GetService("TweenService"):Create(script.Parent.RedLightGreenLight.Doll.Head, TweenInfo.new(0.3), {Orientation = Vector3.new(0, 180, 0)}):Play()
  201.         redLight = true
  202.        
  203.         game.ReplicatedStorage.SquidGameRE:FireAllClients("status", "RED LIGHT", Color3.fromRGB(255, 0, 0))
  204.        
  205.         wait(math.random(1, 5))
  206.        
  207.         game:GetService("TweenService"):Create(script.Parent.RedLightGreenLight.Doll.Head, TweenInfo.new(0.3), {Orientation = Vector3.new(0, 0, 0)}):Play()
  208.         redLight = false
  209.     end
  210.    
  211.    
  212.     for i, player in pairs(playersAlive) do
  213.        
  214.         player.Character.Humanoid.Health = 0
  215.        
  216.         script.Shot:Play()
  217.     end
  218.    
  219.    
  220.     wait(5)
  221.    
  222.    
  223.     --Honeycomb Game
  224.    
  225.     playersAlive = playersCompleted
  226.     playersCompleted = {}
  227.    
  228.    
  229.     game.ReplicatedStorage.SquidGameRE:FireAllClients("status", "CUT THE COOKIE", Color3.fromRGB(255, 255, 255))
  230.    
  231.    
  232.     for i, spawnPart in pairs(script.Parent.Honeycomb.Spawns:GetChildren()) do
  233.        
  234.         local player = playersAlive[i]
  235.        
  236.         if player then
  237.            
  238.             local newBlock = game.ReplicatedStorage.HoneycombTemplate:Clone()
  239.            
  240.             newBlock:SetPrimaryPartCFrame(spawnPart.CFrame)
  241.            
  242.            
  243.             newBlock.Parent = script.Parent.Honeycomb.PlayerCells
  244.            
  245.             player.Character.HumanoidRootPart.CFrame = newBlock.SpawnPart.CFrame
  246.             wait()
  247.             player.Character.HumanoidRootPart.Anchored = true
  248.            
  249.            
  250.             local cookie = game.ReplicatedStorage.HoneycombCookies:GetChildren()[math.random(1, #game.ReplicatedStorage.HoneycombCookies:GetChildren())]:Clone()
  251.             cookie.Name = player.Name .. "Cookie"
  252.             cookie.Parent = script.Parent.Honeycomb.Cookies
  253.             cookie.Shape["1"].Color = Color3.fromRGB(62, 223, 17)
  254.            
  255.             game.ReplicatedStorage.SquidGameRE:FireClient(player, "honeycomb", cookie)
  256.            
  257.            
  258.             cookie.Cookie.ChildAdded:Connect(function()
  259.                
  260.                 if #cookie.Cookie:GetChildren() > 2 then
  261.                    
  262.                     player.Character.Humanoid.Health = 0
  263.                     script.Shot:Play()
  264.                 end
  265.             end)
  266.         end
  267.     end
  268.    
  269.    
  270.    
  271.     local timeLeft = gameLength
  272.    
  273.    
  274.     cookieGame = true
  275.  
  276.     while timeLeft > 0 and #playersAlive > 0 do
  277.  
  278.         timeLeft -= 1
  279.  
  280.         local mins = math.floor(timeLeft / 60)
  281.         local secs = timeLeft % 60
  282.  
  283.         if string.len(mins) < 2 then mins = "0" .. mins end
  284.         if string.len(secs) < 2 then secs = "0" .. secs end
  285.        
  286.         game.ReplicatedStorage.SquidGameRE:FireAllClients("timer", mins .. ":" .. secs)
  287.  
  288.         wait(1)
  289.     end
  290.    
  291.    
  292.     script.Parent.Honeycomb.Cookies:ClearAllChildren()
  293.    
  294.    
  295.     for i, player in pairs(playersAlive) do
  296.  
  297.         player.Character.Humanoid.Health = 0
  298.  
  299.         script.Shot:Play()
  300.     end
  301.    
  302.    
  303.     game.ReplicatedStorage.SquidGameRE:FireAllClients("honeycombEnd")
  304.     cookieGame = false
  305.    
  306.    
  307.     --Reward winners
  308.    
  309.     for i, player in pairs(playersCompleted) do
  310.        
  311.         player.leaderstats.Cash.Value += math.floor(10000 / #playersCompleted)
  312.     end
  313. end
RAW Paste Data