Advertisement
Scripting_King

Untitled

Jun 29th, 2025 (edited)
369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 45.06 KB | Source Code | 0 0
  1. --By the_king_here/lenovo768
  2.  
  3. --[[
  4.    Squid Game Round Manager System
  5.    Handles all round-based logic including Red Light/Green Light, Rope Map with Modes (Easy/Hard), teleportation, gamepasses, and developer products.
  6.    Built using Knit framework.
  7. ]]
  8.  
  9. --SERVICES
  10. local Knit = require(game:GetService("ReplicatedStorage").Packages.Knit)
  11. local Manager = require(game.ServerScriptService.PlayerData.Manager)
  12.  
  13. local TweenService = game:GetService("TweenService")
  14. local RunService = game:GetService("RunService")
  15. local MPS = game:GetService("MarketplaceService")
  16. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  17. local InsertService = game:GetService("InsertService")
  18. local SoundService = game:GetService("SoundService")
  19.  
  20.  
  21. --Remote Events/Signals to communicate with clients/server
  22. local MapHandlerService = Knit.CreateService{
  23.     Name = "MapHandlerService",
  24.     Client = {
  25.         Timer = Knit.CreateSignal(),
  26.         Message = Knit.CreateSignal(),
  27.         AnimateRopes = Knit.CreateSignal(),
  28.         BlockGoingBack = Knit.CreateSignal(),
  29.         RoundEnd = Knit.CreateSignal(),
  30.         NameTag = Knit.CreateSignal(),
  31.         UpdateRewardStatus = Knit.CreateSignal(),
  32.         MusicEvent = Knit.CreateSignal(),
  33.         SquidMusic = Knit.CreateSignal(),
  34.     }
  35. }
  36.  
  37. --VARIABLES
  38. local Maps = workspace:FindFirstChild("Maps")
  39.  
  40. local notificationRemote = ReplicatedStorage.Events:WaitForChild("NotificationRemote")
  41.  
  42. local Light1 = workspace.Maps.DollMap.Light1
  43. local Light2 = workspace.Maps.DollMap.Light2
  44.  
  45. local tweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, 0)
  46. local tweenInfoForMusic = TweenInfo.new(1.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, 0)
  47.  
  48. local RedlightSound = Maps.HadRopeMap.Doll.HumanoidRootPart:FindFirstChild("RedLight")
  49. local GreenLightSound = Maps.HadRopeMap.Doll.HumanoidRootPart:FindFirstChild("GreenLight")
  50.  
  51. local SquidGameMusic = SoundService:FindFirstChild("Music")
  52. local BackgroundMusic = SoundService:FindFirstChild("LobbyMusic")
  53.  
  54. local playerInDollGame = {}
  55. local PlayerInEasyRopeGame = {}
  56. local PlayerInHardRopeGame = {}
  57. local teleportedPlayers = {}
  58. local HardTeleportedPlayers = {}
  59.  
  60. local Products = {
  61.     EliminatePlayers = 3312415657,
  62.     SpeedTroll = 3312416017,
  63.     KillRandomPersonTroll = 3312444642,
  64.     TakeCoinsTroll = 3312417586,
  65. }
  66.  
  67. local PushProducts = {
  68.     Push1 = 3313283431,
  69.     Push2 = 3313283430,
  70.     Push5 = 3313283433,
  71.     Push7 = 3313283424,
  72.     Push10 = 3313286623,
  73. }
  74.  
  75. local ShouldAnimateDoll = false
  76. local ShouldAnimateRopeLight = false
  77.  
  78. local IsRopeGreenLight
  79.  
  80. local EasyRopeAnimationConnection
  81. local HardRopeAnimationConnection
  82. local initialCFrameEasyRope
  83. local initialCFrameHardRope
  84.  
  85. local collider = workspace.Maps.EasyRopemap:WaitForChild("HitRope").PrimaryPart
  86. local collider2 = workspace.Maps.HadRopeMap:WaitForChild("HitRope").PrimaryPart
  87.  
  88. --Function to handle all logics which are neccessory to execute when rope game ends
  89. function MapHandlerService:EndRopeGame(Mode)
  90.     if Mode == "Easy" then
  91.         collider.CFrame = initialCFrameEasyRope
  92.     else
  93.         ShouldAnimateRopeLight = false
  94.         collider2.CFrame = initialCFrameHardRope
  95.     end
  96.  
  97.     SquidGameMusic:Stop()
  98.     if Mode == "Easy" then
  99.         for i, player in pairs(game.Players:GetPlayers()) do
  100.             if player:FindFirstChild("PlayerSelectedMode").Value ~= "Easy" then continue end
  101.             self.Client.RoundEnd:Fire(player, Mode)
  102.         end
  103.     else
  104.         for i, player in pairs(game.Players:GetPlayers()) do
  105.             if player:FindFirstChild("PlayerSelectedMode").Value ~= "Hard" then continue end
  106.             self.Client.RoundEnd:Fire(player, Mode)
  107.         end
  108.     end
  109.  
  110.  
  111.     if Mode == "Easy" then
  112.         local success, errormsg = pcall(function()
  113.             for i, player in pairs(game.Players:GetPlayers()) do
  114.                 if player:FindFirstChild("PlayerSelectedMode").Value ~= "Easy" then continue end
  115.                 local char = player.Character
  116.                 if char then
  117.                     local Humanoid = char:FindFirstChildOfClass("Humanoid")
  118.                     if Humanoid then
  119.                         if Humanoid.Health <= 0 then
  120.                             continue
  121.                         end
  122.                     end
  123.                     self.Client.SquidMusic:Fire(player, "Stop")
  124.                     if (char.PrimaryPart.Position - workspace.Maps.EasyLobby.TeleportPoints.Center.Position).Magnitude > 130 then
  125.                         char:PivotTo(workspace.Maps.EasyLobby.TeleportPoints:GetChildren()[math.random(1, #workspace.Maps.EasyLobby.TeleportPoints:GetChildren())].CFrame)
  126.                     end
  127.                 end
  128.             end
  129.         end)
  130.         EasyRopeAnimationConnection:Disconnect()
  131.         table.clear(teleportedPlayers)
  132.     else
  133.         local success, errormsg = pcall(function()
  134.             for i, player in pairs(game.Players:GetPlayers()) do
  135.                 if player:FindFirstChild("PlayerSelectedMode").Value ~= "Hard" then continue end
  136.                 local char = player.Character
  137.                 if char then
  138.                     local Humanoid = char:FindFirstChildOfClass("Humanoid")
  139.                     if Humanoid then
  140.                         if Humanoid.Health <= 0 then
  141.                             continue
  142.                         end
  143.                     end
  144.                     print("Runned")
  145.                     self.Client.SquidMusic:Fire(player, "Stop")
  146.                     if (char.PrimaryPart.Position - workspace.Maps.HardLobby.TeleportPoints.Center.Position).Magnitude > 130 then
  147.                         char:PivotTo(workspace.Maps.HardLobby.TeleportPoints:GetChildren()[math.random(1, #workspace.Maps.HardLobby.TeleportPoints:GetChildren())].CFrame)
  148.                     end
  149.                 end
  150.             end
  151.         end)
  152.         HardRopeAnimationConnection:Disconnect()
  153.         table.clear(HardTeleportedPlayers)
  154.  
  155.     end
  156. end
  157.  
  158. --Function to count players that are playing hard mode
  159. function MapHandlerService:PlayersInHardMode()
  160.     local Count = 0
  161.     for i, player in pairs(game.Players:GetPlayers()) do
  162.         if player:WaitForChild("PlayerSelectedMode").Value == "Hard" then
  163.             Count += 1
  164.         end
  165.     end
  166.     return Count
  167. end
  168.  
  169. --Function to count players that are playing easy mode
  170. function MapHandlerService:PlayersInEasyMode()
  171.     local Count = 0
  172.     for i, player in pairs(game.Players:GetPlayers()) do
  173.         if player:WaitForChild("PlayerSelectedMode").Value == "Easy" then
  174.             Count += 1
  175.         end
  176.     end
  177.     return Count
  178. end
  179.  
  180.  
  181. --Function to teleport player to the easy/hard rope map
  182. function MapHandlerService:TeleportPlayerToTheMap(MapName)
  183.     local Map = Maps:FindFirstChild(MapName)
  184.     if not Map then warn("No map found with the name: "..MapName) return end
  185.     for i, player in pairs(game.Players:GetPlayers()) do
  186.         if Map.Name == "EasyRopemap" and player:FindFirstChild("PlayerSelectedMode").Value ~= "Easy" then continue end
  187.         if Map.Name == "HadRopeMap" and player:FindFirstChild("PlayerSelectedMode").Value ~= "Hard" then continue end
  188.         local char = player.Character
  189.         if not char then return end
  190.         if Map.Name == "EasyRopemap" or Map.Name == "HadRopeMap" then
  191.             if Map.Name == "EasyRopemap" then
  192.                 table.insert(PlayerInEasyRopeGame, player)
  193.                 local RandomTeleportPoint:BasePart = Map.StartPoints:GetChildren()[math.random(1, #Maps.EasyRopemap.StartPoints:GetChildren())]
  194.                 char:PivotTo(RandomTeleportPoint.CFrame)
  195.             else
  196.                 table.insert(PlayerInHardRopeGame, player)
  197.                 local RandomTeleportPoint:BasePart = Map.StartPoints:GetChildren()[math.random(1, #Maps.HadRopeMap.StartPoints:GetChildren())]
  198.                 char:PivotTo(RandomTeleportPoint.CFrame)
  199.             end
  200.  
  201.             local Humanoid = char:FindFirstChildOfClass("Humanoid")
  202.             if Humanoid then
  203.                 Humanoid.Died:Connect(function()
  204.                     if Map.Name == "EasyRopemap" then
  205.                         if table.find(PlayerInEasyRopeGame, player) then
  206.                             table.remove(PlayerInEasyRopeGame, table.find(PlayerInEasyRopeGame, player))
  207.                         end
  208.                     else
  209.                         if table.find(PlayerInHardRopeGame, player) then
  210.                             table.remove(PlayerInHardRopeGame, table.find(PlayerInHardRopeGame, player))
  211.                         end
  212.                     end
  213.  
  214.                 end)
  215.             end
  216.  
  217.         else
  218.             table.insert(playerInDollGame, player)
  219.         end
  220.     end
  221. end
  222.  
  223.  
  224.  
  225. --function to teleport players to the train track, from where the round will start
  226. function MapHandlerService:TeleportPlayerToInGame(Mode)
  227.     local Map
  228.     if Mode == "Easy" then
  229.         Map = Maps:FindFirstChild("EasyRopemap")
  230.     else
  231.         Map = Maps:FindFirstChild("HadRopeMap")
  232.     end
  233.     if not Map then return end
  234.     if Mode == "Easy" then
  235.         local teleportPoints = Map.InGameTeleport:GetChildren()
  236.         if #teleportPoints == 0 then
  237.             warn("No teleport points found in InGameTeleport1")
  238.             return
  239.         end
  240.  
  241.         local unteleportedPlayers = {}
  242.         for _, player in ipairs(game.Players:GetPlayers()) do
  243.             if player:FindFirstChild("PlayerSelectedMode").Value ~= "Easy" then continue end
  244.             if not table.find(teleportedPlayers, player) then
  245.                 table.insert(unteleportedPlayers, player)
  246.             end
  247.         end
  248.  
  249.         if #unteleportedPlayers == 0 then
  250.             warn("All players have already been teleported.")
  251.             return
  252.         end
  253.  
  254.         local function ShuffleArray(array)
  255.             for i = #array, 2, -1 do
  256.                 local j = math.random(1, i)
  257.                 array[i], array[j] = array[j], array[i]
  258.             end
  259.         end
  260.  
  261.         ShuffleArray(unteleportedPlayers)
  262.  
  263.  
  264.         for i = 1, self:PlayersInEasyMode() - #teleportedPlayers do
  265.             local player = unteleportedPlayers[i]
  266.             local char = player.Character
  267.             local teleportPoint = teleportPoints[1]
  268.  
  269.             if player and char and teleportPoint then
  270.                 char:PivotTo(teleportPoint.CFrame)
  271.                 table.insert(playerInDollGame, player)
  272.                 table.insert(teleportedPlayers, player)
  273.             end
  274.         end
  275.     else
  276.         local teleportPoints = Map.InGameTeleport:GetChildren()
  277.         if #teleportPoints == 0 then
  278.             warn("No teleport points found in InGameTeleport1")
  279.             return
  280.         end
  281.  
  282.         local unteleportedPlayers = {}
  283.         for _, player in ipairs(game.Players:GetPlayers()) do
  284.             if player:FindFirstChild("PlayerSelectedMode").Value ~= "Hard" then continue end
  285.             if not table.find(HardTeleportedPlayers, player) then
  286.                 table.insert(unteleportedPlayers, player)
  287.             end
  288.         end
  289.  
  290.         if #unteleportedPlayers == 0 then
  291.             warn("All players have already been teleported.")
  292.             return
  293.         end
  294.  
  295.         local function ShuffleArray(array)
  296.             for i = #array, 2, -1 do
  297.                 local j = math.random(1, i)
  298.                 array[i], array[j] = array[j], array[i]
  299.             end
  300.         end
  301.  
  302.         ShuffleArray(unteleportedPlayers)
  303.  
  304.  
  305.         for i = 1, self:PlayersInHardMode() - #HardTeleportedPlayers do
  306.             local player = unteleportedPlayers[i]
  307.             local char = player.Character
  308.             local teleportPoint = teleportPoints[1]
  309.  
  310.             if player and char and teleportPoint then
  311.                 char:PivotTo(teleportPoint.CFrame)
  312.                 table.insert(playerInDollGame, player)
  313.                 table.insert(HardTeleportedPlayers, player)
  314.             end
  315.         end
  316.     end
  317. end
  318.  
  319.  
  320. --Controls RedLight / GreenLight logic including player speed checks and win detection
  321. function MapHandlerService:AnimateDoll()
  322.     local Doll = Maps.DollMap:FindFirstChild("Doll")
  323.     local RedLightSound = Doll.HumanoidRootPart.RedLight
  324.     local GreenLightSound = Doll.HumanoidRootPart.GreenLight
  325.     local IsGreenLight = true
  326.     GreenLightSound:Play()
  327.     TweenService:Create(Doll.Model.PrimaryPart, tweenInfo, {CFrame = Doll.Model.PrimaryPart.CFrame * CFrame.Angles(0, math.rad(180), 0)}):Play()
  328.     task.spawn(function()
  329.         while wait(0.1) do
  330.             if IsGreenLight then continue end
  331.             if not ShouldAnimateDoll then break end
  332.             for i, player in pairs(playerInDollGame) do
  333.                 local char = player.Character
  334.                 if not char then return end
  335.                 if char.PrimaryPart.AssemblyLinearVelocity.Magnitude > 4 then
  336.                     task.delay(0.4, function()
  337.                         if char.PrimaryPart.AssemblyLinearVelocity.Magnitude > 4 then
  338.                             local Humanoid = char:FindFirstChildOfClass("Humanoid")
  339.                             Humanoid:TakeDamage(Humanoid.MaxHealth)
  340.                         end
  341.                     end)
  342.                 end
  343.             end
  344.         end
  345.     end)
  346.     local FinishPart = Maps.DollMap:FindFirstChild("FinishPart")
  347.  
  348.     FinishPart.Touched:Connect(function(hit)
  349.         local player = game.Players:GetPlayerFromCharacter(hit.Parent)
  350.         if not player then player = game.Players:GetPlayerFromCharacter(hit.Parent.Parent) end
  351.         if not player then return end
  352.         if not table.find(playerInDollGame, player) then return end
  353.         self.Client.Message:Fire(player, "You Won!")
  354.         player.leaderstats.Wins.Value += 1
  355.         if table.find(playerInDollGame, player) then
  356.             table.remove(playerInDollGame, table.find(playerInDollGame, player))
  357.         end
  358.         if #playerInDollGame == 0 then
  359.             ShouldAnimateDoll = false
  360.             wait(1)
  361.  
  362.             local rootLookVector = Doll.HumanoidRootPart.CFrame.LookVector
  363.             local dollLookVector = Doll.Model.PrimaryPart.CFrame.LookVector
  364.  
  365.             local dot = rootLookVector:Dot(dollLookVector)
  366.  
  367.             if dot < 0 then
  368.                 local tweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
  369.                 local targetCFrame = Doll.Model.PrimaryPart.CFrame * CFrame.Angles(0, math.rad(180), 0)
  370.  
  371.                 TweenService:Create(Doll.Model.PrimaryPart, tweenInfo, {CFrame = targetCFrame}):Play()
  372.             end
  373.         end
  374.     end)
  375.  
  376.     task.spawn(function()
  377.         while ShouldAnimateDoll do
  378.             if not IsGreenLight then
  379.                 wait(math.random(2, 5))
  380.                 if not ShouldAnimateDoll then break end
  381.                 if Doll.Model.PrimaryPart then
  382.                     GreenLightSound:Play()
  383.                     TweenService:Create(Doll.Model.PrimaryPart, tweenInfo, {CFrame = Doll.Model.PrimaryPart.CFrame * CFrame.Angles(0, math.rad(180), 0)}):Play()
  384.                     Light1.light.Color = Color3.fromRGB(0, 255, 0)
  385.                     Light2.light.Color = Color3.fromRGB(0, 255, 0)
  386.                 end
  387.                 IsGreenLight = true
  388.             else
  389.                 wait(math.random(2,5))
  390.                 if not ShouldAnimateDoll then break end
  391.                 if Doll.Model.PrimaryPart then
  392.                     RedLightSound:Play()
  393.                     TweenService:Create(Doll.Model.PrimaryPart, tweenInfo, {CFrame = Doll.Model.PrimaryPart.CFrame * CFrame.Angles(0, math.rad(-180), 0)}):Play()
  394.                     Light1.light.Color = Color3.fromRGB(196, 40, 28)
  395.                     Light2.light.Color = Color3.fromRGB(196, 40, 28)
  396.                 end
  397.                 IsGreenLight = false
  398.             end
  399.         end
  400.     end)
  401. end
  402.  
  403. --shape the simple seconds into Minutes:Seconds Formate like 00:00
  404. function MapHandlerService:FormatTime(seconds)
  405.     seconds = math.max(0, math.floor(seconds))
  406.  
  407.     local minutes = math.floor(seconds / 60)
  408.     local secs = seconds % 60
  409.  
  410.     return string.format("%02d:%02d", minutes, secs)
  411. end
  412.  
  413.  
  414. --Handle all of the developer products after it's been purchased
  415. function MapHandlerService:DeveloperProductsHandler()
  416.     MPS.PromptProductPurchaseFinished:Connect(function(userId, ProductId, IsPurchased)
  417.         if not IsPurchased then return end
  418.         print("Runned", IsPurchased, ProductId)
  419.         local Buyer = game.Players:GetPlayerByUserId(userId)
  420.         if ProductId == Products.EliminatePlayers then
  421.             for i, player in pairs(game.Players:GetPlayers()) do
  422.                 if player ~= Buyer then
  423.                     local char = player.Character
  424.                     local Humanoid = char:FindFirstChildOfClass("Humanoid")
  425.                     if not Humanoid then return end
  426.                     Humanoid:TakeDamage(Humanoid.MaxHealth)
  427.                     notificationRemote:FireClient(player, "You Got Trolled!", {Bad = false})
  428.                 end
  429.             end
  430.         elseif ProductId == Products.KillRandomPersonTroll then
  431.             local players = game.Players:GetPlayers()
  432.             if #players > 1 then
  433.                 local randomPlayer = players[math.random(1, #players)]
  434.                 repeat
  435.                     wait()
  436.                     randomPlayer = players[math.random(1, #players)]
  437.                 until randomPlayer ~= Buyer
  438.                 local char = randomPlayer.Character
  439.                 local Humanoid = char:FindFirstChildOfClass("Humanoid")
  440.                 if not Humanoid then return end
  441.                 Humanoid:TakeDamage(Humanoid.MaxHealth)
  442.             end
  443.         elseif ProductId == Products.SpeedTroll then
  444.             for i, player in pairs(game.Players:GetPlayers()) do
  445.                 if player ~= Buyer then
  446.                     local char = player.Character
  447.                     local Humanoid = char:FindFirstChildOfClass("Humanoid")
  448.                     if not Humanoid then return end
  449.                     Humanoid.WalkSpeed = 100
  450.                     delay(30, function()
  451.                         if player and Humanoid then
  452.                             Humanoid.WalkSpeed = 16
  453.                         end
  454.                     end)
  455.                     notificationRemote:FireClient(player, "You Got Trolled!", {Bad = false})
  456.                 end
  457.             end
  458.         elseif ProductId == Products.TakeCoinsTroll then
  459.             local TookCoins = 0
  460.             for i, player in pairs(game.Players:GetPlayers()) do
  461.                 if player ~= Buyer then
  462.                     local leaderstats = player:FindFirstChild("leaderstats")
  463.                     local Coins = leaderstats:FindFirstChild("Coins")
  464.                     if not Coins then return end
  465.                     if Coins.Value >= 10 then
  466.                         Coins.Value -= 10
  467.                         TookCoins += 10
  468.                     else
  469.                         TookCoins += Coins.Value
  470.                         Coins.Value = 0
  471.                     end
  472.                     notificationRemote:FireClient(player, "Someone Took Your Coins, Happy Troll!", {Bad = false})
  473.                 end
  474.                 local BuyerLeaderstats = Buyer:FindFirstChild("leaderstats")
  475.                 local Coins = Buyer:FindFirstChild("Coins")
  476.                 if Coins then
  477.                     Coins.Value += TookCoins
  478.                 end
  479.             end
  480.         elseif ProductId == PushProducts.Push1 then
  481.             local PlayerPushes = Buyer:FindFirstChild("Pushes")
  482.             if PlayerPushes then
  483.                 PlayerPushes.Value += 1
  484.             else
  485.                 print("Player Pushes not found")
  486.             end
  487.         elseif ProductId == PushProducts.Push2 then
  488.             local PlayerPushes = Buyer:FindFirstChild("Pushes")
  489.             if PlayerPushes then
  490.                 PlayerPushes.Value += 2
  491.             end
  492.         elseif ProductId == PushProducts.Push5 then
  493.             local PlayerPushes = Buyer:FindFirstChild("Pushes")
  494.             if PlayerPushes then
  495.                 PlayerPushes.Value += 5
  496.             end
  497.         elseif ProductId == PushProducts.Push7 then
  498.             local PlayerPushes = Buyer:FindFirstChild("Pushes")
  499.             if PlayerPushes then
  500.                 PlayerPushes.Value += 7
  501.             end
  502.         elseif ProductId == PushProducts.Push10 then
  503.             local PlayerPushes = Buyer:FindFirstChild("Pushes")
  504.             if PlayerPushes then
  505.                 PlayerPushes.Value += 10
  506.             end
  507.         elseif ProductId == 3314212399 then
  508.             local Coins = Buyer:WaitForChild("leaderstats"):WaitForChild("Coins")
  509.             if Coins then
  510.                 Coins.Value += 50
  511.             end
  512.         elseif ProductId == 3314212620 then
  513.             local Coins = Buyer:WaitForChild("leaderstats"):WaitForChild("Coins")
  514.             if Coins then
  515.                 Coins.Value += 100
  516.             end
  517.         elseif ProductId == 3314213085 then
  518.             local Coins = Buyer:WaitForChild("leaderstats"):WaitForChild("Coins")
  519.             if Coins then
  520.                 Coins.Value += 300
  521.             end
  522.         elseif ProductId == 3314213295 then
  523.             local Coins = Buyer:WaitForChild("leaderstats"):WaitForChild("Coins")
  524.             if Coins then
  525.                 Coins.Value += 500
  526.             end
  527.         elseif ProductId == 3314214142 then
  528.             local Coins = Buyer:WaitForChild("leaderstats"):WaitForChild("Coins")
  529.             if Coins then
  530.                 Coins.Value += 1000
  531.             end
  532.         elseif ProductId == 3314996213 then
  533.             local ExtraLifes = Buyer:FindFirstChild("ExtraLifes")
  534.             if ExtraLifes then
  535.                 ExtraLifes.Value += 1
  536.             end
  537.         elseif ProductId == 3314996574 then
  538.             local LessGravity = Buyer:FindFirstChild("LessGravity")
  539.             if LessGravity then
  540.                 LessGravity.Value += 1
  541.             end
  542.         elseif ProductId == 3314996930 then
  543.             self.Client.NameTag:Fire(Buyer)
  544.         end
  545.     end)
  546. end
  547.  
  548. --function to apply rainbow type animation to specific label/name tag
  549. function MapHandlerService:applyRainbowTween(label)
  550.  
  551.  
  552.     local rainbow = label
  553.     local grad = rainbow.UIGradient
  554.  
  555.     local counter = 0  
  556.     local w = math.pi / 12  
  557.     local CS = {}      
  558.     local num = 15  
  559.     local frames = 0
  560.  
  561.     RunService.Heartbeat:Connect(function()
  562.         if math.fmod(frames, 2) == 0 then
  563.             for i = 0, num do
  564.                 local c = Color3.fromRGB(127 * math.sin(w*i + counter) + 128, 127 * math.sin(w*i + 2 * math.pi/3 + counter) + 128, 127*math.sin(w*i + 4*math.pi/3 + counter) + 128)
  565.                 table.insert(CS, i+1, ColorSequenceKeypoint.new(i/num, c))
  566.             end
  567.             grad.Color = ColorSequence.new(CS)
  568.             CS = {}
  569.             counter = counter - math.pi/40
  570.             if (counter >= math.pi * 2) then
  571.                 counter = 0
  572.             end
  573.         end
  574.         if frames >= 1000 then
  575.             frames = 0
  576.         end
  577.         frames = frames + 1
  578.     end)
  579. end
  580.  
  581. --function to handle gamepasses after been purchased
  582. function MapHandlerService:HandleGamepasses()
  583.     MPS.PromptGamePassPurchaseFinished:Connect(function(UserId, ganmepassId, IsPurchased)
  584.         if not IsPurchased then return end
  585.         local player = game.Players:GetPlayerByUserId(UserId)
  586.         if ganmepassId == 1274510513 then
  587.             local NameTag = ReplicatedStorage.Assets:FindFirstChild("nametagui")
  588.             if NameTag then
  589.  
  590.                 if player.Character:FindFirstChild("Head"):FindFirstChild(NameTag.Name) then
  591.                     player.Character:FindFirstChild("Head"):FindFirstChild(NameTag.Name):Destroy()
  592.                 end
  593.  
  594.                 local CloneNameTag = NameTag:Clone()
  595.                 CloneNameTag.Parent = player.Character:FindFirstChild("Head")
  596.                 CloneNameTag.ntframe.username.Text = player.Name
  597.  
  598.                 self:applyRainbowTween(CloneNameTag.ntframe.username)
  599.             end
  600.         end
  601.     end)
  602. end
  603.  
  604. --This function checks whether a player is walking, and if so, eliminates them, It ignores players who are jumping by only getting horizontal velocity components and excluding the vertical axis.
  605. function MapHandlerService:KillIfWalking(player:Player)
  606.     local character = player.Character
  607.     if not character or not character:FindFirstChild("HumanoidRootPart") or not character:FindFirstChild("Humanoid") or character:FindFirstChildOfClass("Humanoid").Health <= 0 then
  608.         return
  609.     end
  610.  
  611.     if IsRopeGreenLight then return end
  612.  
  613.     local hrp = character.HumanoidRootPart
  614.     local velocity = hrp.AssemblyLinearVelocity
  615.  
  616.     local horizontalSpeed = Vector3.new(velocity.X, 0, velocity.Z).Magnitude
  617.     local verticalSpeed = velocity.Y
  618.  
  619.     local HORIZONTAL_SPEED_THRESHOLD = 3
  620.     local VERTICAL_JUMP_LIMIT = 10
  621.     if horizontalSpeed > HORIZONTAL_SPEED_THRESHOLD then
  622.         task.delay(0.5, function()
  623.             velocity = hrp.AssemblyLinearVelocity
  624.             horizontalSpeed = Vector3.new(velocity.X, 0, velocity.Z).Magnitude
  625.             verticalSpeed = velocity.Y
  626.             if horizontalSpeed > HORIZONTAL_SPEED_THRESHOLD then
  627.                 character.Humanoid.Health = 0
  628.             end
  629.         end)
  630.     end
  631. end
  632.  
  633.  
  634. --it animates red/green lights for rope map
  635. function MapHandlerService:AnimateLights()
  636.     local RedLight = workspace.Maps.HadRopeMap.Light.RedLight.Part
  637.     local GreenLight = workspace.Maps.HadRopeMap.Light.GreenLight.Part
  638.  
  639.     ShouldAnimateRopeLight = true
  640.     task.spawn(function()
  641.         RedLight.Material = Enum.Material.SmoothPlastic
  642.         RedLight.Color = Color3.new(0, 0, 0)
  643.         GreenLight.Material = Enum.Material.Neon
  644.         GreenLight.Color = Color3.new(0, 1, 0)
  645.         IsRopeGreenLight = true
  646.         GreenLightSound:Play()
  647.         local Success, Pcall = pcall(function()
  648.             for i, player in pairs(PlayerInHardRopeGame) do
  649.                 local playerGui = player.PlayerGui
  650.                 if playerGui then
  651.                     local GreenFrame = playerGui.LightUI:FindFirstChild("GreenFrame")
  652.                     local RedFrame = playerGui.LightUI:FindFirstChild("RedFrame")
  653.                     if GreenFrame then
  654.                         GreenFrame.Visible = true
  655.                         RedFrame.Visible = false
  656.                         task.delay(1.5, function()
  657.                             GreenFrame.Visible = false
  658.                             RedFrame.Visible = false
  659.                         end)
  660.                     end
  661.                 end
  662.             end
  663.         end)
  664.         wait(2)
  665.         local Success, Pcall = pcall(function()
  666.             while ShouldAnimateRopeLight do
  667.                 warn("loop running")
  668.  
  669.                 wait(math.random(4, 7))
  670.                 if not IsRopeGreenLight then
  671.                     if not ShouldAnimateRopeLight then
  672.                         break
  673.                     end
  674.                     RedLight.Material = Enum.Material.SmoothPlastic
  675.                     RedLight.Color = Color3.new(0, 0, 0)
  676.                     GreenLight.Material = Enum.Material.Neon
  677.                     GreenLight.Color = Color3.new(0, 1, 0)
  678.                     GreenLightSound:Play()
  679.                     IsRopeGreenLight = true
  680.                     for i, player in pairs(PlayerInHardRopeGame) do
  681.                         local playerGui = player.PlayerGui
  682.                         if playerGui then
  683.                             local GreenFrame = playerGui.LightUI:FindFirstChild("GreenFrame")
  684.                             local RedFrame = playerGui.LightUI:FindFirstChild("RedFrame")
  685.                             if GreenFrame then
  686.                                 GreenFrame.Visible = true
  687.                                 RedFrame.Visible = false
  688.                                 task.delay(1.5, function()
  689.                                     GreenFrame.Visible = false
  690.                                     RedFrame.Visible = false
  691.                                 end)
  692.                             end
  693.                         end
  694.                     end
  695.                 else
  696.                     if not ShouldAnimateRopeLight then
  697.                         break
  698.                     end
  699.                     RedLight.Material = Enum.Material.Neon
  700.                     RedLight.Color = Color3.new(1, 0, 0)
  701.                     GreenLight.Material = Enum.Material.SmoothPlastic
  702.                     GreenLight.Color = Color3.new(0, 0, 0)
  703.                     RedlightSound:Play()
  704.                     IsRopeGreenLight = false
  705.                     for i, player in pairs(PlayerInHardRopeGame) do
  706.                         local playerGui = player.PlayerGui
  707.                         if playerGui then
  708.                             local GreenFrame = playerGui.LightUI:FindFirstChild("GreenFrame")
  709.                             local RedFrame = playerGui.LightUI:FindFirstChild("RedFrame")
  710.                             if GreenFrame then
  711.                                 GreenFrame.Visible = false
  712.                                 RedFrame.Visible = true
  713.                                 task.delay(1.5, function()
  714.                                     GreenFrame.Visible = false
  715.                                     RedFrame.Visible = false
  716.                                 end)
  717.                             end
  718.                         end
  719.                     end
  720.                 end
  721.             end
  722.             RedLight.Material = Enum.Material.SmoothPlastic
  723.             RedLight.Color = Color3.new(0, 0, 0)
  724.             GreenLight.Material = Enum.Material.SmoothPlastic
  725.             GreenLight.Color = Color3.new(0, 0, 0)
  726.         end)
  727.     end)
  728. end
  729.  
  730. --This function gives player extra life if player owns some extra lifes, if player accidently falls down it automatically teleport player back to the nearest checkpoints on the train track
  731. function MapHandlerService:TeleportToNearestCheckpoint(player, checkpoints)
  732.     if not player or not player.Character or not player.Character:FindFirstChild("HumanoidRootPart") then
  733.         warn("Invalid player or character not fully loaded.")
  734.         return
  735.     end
  736.  
  737.     local rootPart = player.Character.HumanoidRootPart
  738.     local closestCheckpoint = nil
  739.     local shortestDistanceSq = math.huge
  740.  
  741.     for _, checkpoint in ipairs(checkpoints) do
  742.         local checkpointPosition
  743.  
  744.         if checkpoint:IsA("Model") then
  745.             if checkpoint.PrimaryPart then
  746.                 checkpointPosition = checkpoint.PrimaryPart.Position
  747.             else
  748.                 warn("Checkpoint model has no PrimaryPart.")
  749.                 continue
  750.             end
  751.         elseif checkpoint:IsA("BasePart") then
  752.             checkpointPosition = checkpoint.Position
  753.         else
  754.             warn("Checkpoint is not a valid BasePart or Model.")
  755.             continue
  756.         end
  757.  
  758.         local distanceSq = (rootPart.Position - checkpointPosition).Magnitude ^ 2
  759.  
  760.         if distanceSq < shortestDistanceSq then
  761.             shortestDistanceSq = distanceSq
  762.             closestCheckpoint = checkpoint
  763.         end
  764.     end
  765.  
  766.     if closestCheckpoint then
  767.         local destination
  768.  
  769.         if closestCheckpoint:IsA("Model") and closestCheckpoint.PrimaryPart then
  770.             destination = closestCheckpoint.PrimaryPart.Position
  771.         elseif closestCheckpoint:IsA("BasePart") then
  772.             destination = closestCheckpoint.Position
  773.         end
  774.         rootPart.CFrame = CFrame.new(destination)
  775.     else
  776.         warn("No valid checkpoints found.")
  777.     end
  778. end
  779.  
  780.  
  781. --[[
  782. This function controls the main rope map round and handles the rope animation. It also uses a timing trick, it sends the animation command to clients a few seconds early along with the start time,
  783. Then when that time comes, all clients play the animation at the same moment, which helps avoid lag caused by ping
  784. ]]
  785. function MapHandlerService:RopeMap(Mode)
  786.     if Mode == "Easy" then
  787.         self:TeleportPlayerToTheMap("EasyRopemap")
  788.     else
  789.         self:TeleportPlayerToTheMap("HadRopeMap")
  790.     end
  791.     wait(8)
  792.     self:TeleportPlayerToInGame(Mode)
  793.  
  794.     local delayBeforeStart = 3
  795.     local startTime = workspace:GetServerTimeNow() + delayBeforeStart
  796.  
  797.     if Mode == "Easy" then
  798.         spawn(function()
  799.             while wait(1) do
  800.                 if #PlayerInEasyRopeGame == 0 then
  801.                     wait(5)
  802.                     table.clear(PlayerInEasyRopeGame)
  803.                     self:EndRopeGame(Mode)
  804.                     break
  805.                 end
  806.             end
  807.         end)
  808.     else
  809.         spawn(function()
  810.             while wait(1) do
  811.                 if #PlayerInHardRopeGame == 0 then
  812.                     wait(5)
  813.                     table.clear(PlayerInHardRopeGame)
  814.                     self:EndRopeGame(Mode)
  815.                     break
  816.                 end
  817.             end
  818.         end)
  819.     end
  820.  
  821.  
  822.     if Mode == "Easy" then
  823.         for i, player in pairs(PlayerInEasyRopeGame) do
  824.             self.Client.SquidMusic:Fire(player, "Play")
  825.         end
  826.     else
  827.         for i, player in pairs(PlayerInHardRopeGame) do
  828.             self.Client.SquidMusic:Fire(player, "Play")
  829.         end
  830.     end
  831.  
  832.  
  833.     spawn(function()
  834.         local accelTime = 3
  835.         local maxSpeed
  836.         if Mode == "Easy" then
  837.             initialCFrameEasyRope = collider.CFrame
  838.             maxSpeed = math.rad(250)
  839.         else
  840.             initialCFrameHardRope = collider2.CFrame
  841.             maxSpeed = math.rad(210)
  842.         end
  843.  
  844.         local IsPrinted = false
  845.  
  846.         if Mode == "Easy" then
  847.             EasyRopeAnimationConnection = RunService.Heartbeat:Connect(function()
  848.                 local now = workspace:GetServerTimeNow()
  849.                 if now < startTime then return end
  850.                 if not IsPrinted then
  851.                     IsPrinted = true
  852.                     warn("[Server] Started: ",now, startTime)
  853.                 end
  854.  
  855.                 local elapsed = now - startTime
  856.                 local rotation
  857.  
  858.                 if elapsed < accelTime then
  859.                     local progress = elapsed / accelTime
  860.                     rotation = 0.33 * maxSpeed * (progress ^ 3) * accelTime
  861.                 else
  862.                     local constantTime = elapsed - accelTime
  863.                     rotation = 0.33 * maxSpeed * accelTime + maxSpeed * constantTime
  864.                 end
  865.  
  866.  
  867.                 local newCFrame = initialCFrameEasyRope * CFrame.Angles(rotation, 0, 0)
  868.                 collider.CFrame = newCFrame
  869.             end)
  870.         else
  871.             HardRopeAnimationConnection = RunService.Heartbeat:Connect(function()
  872.                 local now = workspace:GetServerTimeNow()
  873.                 if now < startTime then return end
  874.                 if not IsPrinted then
  875.                     IsPrinted = true
  876.                     warn("[Server] Started: ",now, startTime)
  877.                 end
  878.  
  879.                 local elapsed = now - startTime
  880.                 local rotation
  881.  
  882.                 if elapsed < accelTime then
  883.                     local progress = elapsed / accelTime
  884.                     rotation = 0.33 * maxSpeed * (progress ^ 3) * accelTime
  885.                 else
  886.                     local constantTime = elapsed - accelTime
  887.                     rotation = 0.33 * maxSpeed * accelTime + maxSpeed * constantTime
  888.                 end
  889.  
  890.  
  891.                 local newCFrame = initialCFrameHardRope * CFrame.Angles(rotation, 0, 0)
  892.                 collider2.CFrame = newCFrame
  893.                 for i, player in pairs(PlayerInHardRopeGame) do
  894.                     self:KillIfWalking(player)
  895.                 end
  896.             end)
  897.         end
  898.     end)
  899.     if Mode == "Easy" then
  900.         for i, player in pairs(PlayerInEasyRopeGame) do
  901.             self.Client.AnimateRopes:Fire(player, startTime, "Easy")
  902.         end
  903.     else
  904.         for i, player in pairs(PlayerInHardRopeGame) do
  905.             self.Client.AnimateRopes:Fire(player, startTime, "Hard")
  906.         end
  907.     end
  908.  
  909.     if Mode == "Hard" then
  910.         self:AnimateLights()
  911.     end
  912.  
  913.     spawn(function()
  914.         if Mode == "Easy" then
  915.             for i = 2 * 60, 0, -1 do
  916.                 wait(1)
  917.                 local FormatedTime = self:FormatTime(i)
  918.                 Maps.EasyRopemap.Timer.Part.SurfaceGui.TextLabel.Text = FormatedTime
  919.                 if #PlayerInEasyRopeGame == 0 or i == 0 then
  920.                     self:EndRopeGame(Mode)
  921.                     table.clear(PlayerInEasyRopeGame)
  922.                     break
  923.                 end
  924.             end
  925.         else
  926.             for i = 2 * 60, 0, -1 do
  927.                 wait(1)
  928.                 local FormatedTime = self:FormatTime(i)
  929.                 Maps.HadRopeMap.Timer.Part.SurfaceGui.TextLabel.Text = FormatedTime
  930.                 if #PlayerInHardRopeGame == 0 or i == 0 then
  931.                     self:EndRopeGame(Mode)
  932.                     table.clear(PlayerInHardRopeGame)
  933.                     break
  934.                 end
  935.             end
  936.         end
  937.     end)
  938.  
  939.     local Connection
  940.     local Connection2
  941.     local Connection3
  942.  
  943.     if Mode == "Easy" then
  944.         Connection = workspace.Maps.EasyRopemap.FinishPoint.Touched:Connect(function(hit)
  945.             local player = game.Players:GetPlayerFromCharacter(hit.Parent) or game.Players:GetPlayerFromCharacter(hit.Parent.Parent)
  946.             if player then
  947.                 if not table.find(PlayerInEasyRopeGame, player) then return end
  948.                 local find = table.find(PlayerInEasyRopeGame, player)
  949.                 table.remove(PlayerInEasyRopeGame, find)
  950.                 player:WaitForChild("leaderstats"):WaitForChild("Wins").Value += 1
  951.                 player:WaitForChild("leaderstats"):WaitForChild("Coins").Value += 50
  952.  
  953.                 if #PlayerInEasyRopeGame == 0 then
  954.                     self:EndRopeGame(Mode)
  955.                     table.clear(PlayerInEasyRopeGame)
  956.                     Connection:Disconnect()
  957.                     Connection2:Disconnect()
  958.                     Connection3:Disconnect()
  959.                 end
  960.             end
  961.         end)
  962.  
  963.         Connection2 = workspace.Maps.EasyRopemap.BlockGoingBack.Touched:Connect(function(hit)
  964.             local player = game.Players:GetPlayerFromCharacter(hit.Parent) or game.Players:GetPlayerFromCharacter(hit.Parent.Parent)
  965.             if player then
  966.                 self.Client.BlockGoingBack:Fire(player, Mode)
  967.             end
  968.         end)
  969.  
  970.         Connection3 = workspace.Maps.EasyRopemap.ExtraLifesChecker.Touched:Connect(function(hit)
  971.             local player = game.Players:GetPlayerFromCharacter(hit.Parent) or game.Players:GetPlayerFromCharacter(hit.Parent.Parent)
  972.             if player then
  973.                 local ExtraLifes = player:FindFirstChild("ExtraLifes")
  974.                 if ExtraLifes.Value == 0 then return end
  975.                 ExtraLifes.Value -= 1
  976.                 self:TeleportToNearestCheckpoint(player, Maps.EasyRopemap.Checkpoints:GetChildren())
  977.             end
  978.         end)
  979.     else
  980.         Connection = workspace.Maps.HadRopeMap.FinishPoint.Touched:Connect(function(hit)
  981.             local player = game.Players:GetPlayerFromCharacter(hit.Parent) or game.Players:GetPlayerFromCharacter(hit.Parent.Parent)
  982.             if player then
  983.                 if not table.find(PlayerInHardRopeGame, player) then return end
  984.                 local find = table.find(PlayerInHardRopeGame, player)
  985.                 table.remove(PlayerInHardRopeGame, find)
  986.                 player:WaitForChild("leaderstats"):WaitForChild("Wins").Value += 1
  987.                 player:WaitForChild("leaderstats"):WaitForChild("Coins").Value += 50
  988.  
  989.                 if #PlayerInHardRopeGame == 0 then
  990.                     self:EndRopeGame(Mode)
  991.                     table.clear(PlayerInHardRopeGame)
  992.                     Connection:Disconnect()
  993.                     Connection2:Disconnect()
  994.                     Connection3:Disconnect()
  995.                 end
  996.             end
  997.         end)
  998.  
  999.         Connection2 = workspace.Maps.HadRopeMap.BlockGoingBack.Touched:Connect(function(hit)
  1000.             local player = game.Players:GetPlayerFromCharacter(hit.Parent) or game.Players:GetPlayerFromCharacter(hit.Parent.Parent)
  1001.             if player then
  1002.                 self.Client.BlockGoingBack:Fire(player, Mode)
  1003.             end
  1004.         end)
  1005.  
  1006.         Connection3 = workspace.Maps.HadRopeMap.ExtraLifesChecker.Touched:Connect(function(hit)
  1007.             local player = game.Players:GetPlayerFromCharacter(hit.Parent) or game.Players:GetPlayerFromCharacter(hit.Parent.Parent)
  1008.             if player then
  1009.                 local ExtraLifes = player:FindFirstChild("ExtraLifes")
  1010.                 if ExtraLifes.Value == 0 then return end
  1011.                 ExtraLifes.Value -= 1
  1012.                 self:TeleportToNearestCheckpoint(player, Maps.HadRopeMap.Checkpoints:GetChildren())
  1013.             end
  1014.         end)
  1015.     end
  1016.  
  1017. end
  1018.  
  1019.  
  1020. --this function handles the main working of doll map round system
  1021. function MapHandlerService:DollMap()
  1022.     self:TeleportPlayerToTheMap("DollMap")
  1023.     local Doll = Maps.DollMap:FindFirstChild("Doll")
  1024.  
  1025.  
  1026.     for i, player in pairs(playerInDollGame) do
  1027.         self.Client.Timer:Fire(player)
  1028.  
  1029.         local char = player.Character
  1030.         if not char then continue end
  1031.         local Humanoid = char:FindFirstChildOfClass("Humanoid")
  1032.         if Humanoid then
  1033.             Humanoid.Died:Connect(function()
  1034.                 if table.find(playerInDollGame, player) then
  1035.                     table.remove(playerInDollGame, table.find(playerInDollGame, player))
  1036.                 end
  1037.                 if #playerInDollGame == 0 then
  1038.                     ShouldAnimateDoll = false
  1039.                     wait(2)
  1040.  
  1041.                     local rootLookVector = Doll.HumanoidRootPart.CFrame.LookVector
  1042.                     local dollLookVector = Doll.Model.PrimaryPart.CFrame.LookVector
  1043.  
  1044.                     local dot = rootLookVector:Dot(dollLookVector)
  1045.  
  1046.                     if dot < 0 then
  1047.                         local tweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
  1048.                         local targetCFrame = Doll.Model.PrimaryPart.CFrame * CFrame.Angles(0, math.rad(180), 0)
  1049.  
  1050.                         TweenService:Create(Doll.Model.PrimaryPart, tweenInfo, {CFrame = targetCFrame}):Play()
  1051.                     end
  1052.                 end
  1053.             end)
  1054.         end
  1055.     end
  1056.     wait(7)
  1057.     Maps.DollMap.InvisiblePart.CanCollide = false
  1058.     ShouldAnimateDoll = true
  1059.     self:AnimateDoll()
  1060.  
  1061.     spawn(function()
  1062.         for i = 3 * 60, 0, -1 do
  1063.             local FormatedTime = self:FormatTime(i)
  1064.             Maps.DollMap.LCD.Part.SurfaceGui.TextLabel.Text = FormatedTime
  1065.             wait(1)
  1066.             if #playerInDollGame == 0 then
  1067.                 ShouldAnimateDoll = false
  1068.                 wait(1)
  1069.  
  1070.                 local rootLookVector = Doll.HumanoidRootPart.CFrame.LookVector
  1071.                 local dollLookVector = Doll.Model.PrimaryPart.CFrame.LookVector
  1072.  
  1073.                 local dot = rootLookVector:Dot(dollLookVector)
  1074.  
  1075.                 if dot < 0 then
  1076.                     local tweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
  1077.                     local targetCFrame = Doll.Model.PrimaryPart.CFrame * CFrame.Angles(0, math.rad(180), 0)
  1078.  
  1079.                     TweenService:Create(Doll.Model.PrimaryPart, tweenInfo, {CFrame = targetCFrame}):Play()
  1080.                 end
  1081.                 break
  1082.             end
  1083.         end
  1084.  
  1085.         if #playerInDollGame ~= 0 then
  1086.             for i, player in pairs(playerInDollGame) do
  1087.                 local char = player.Character
  1088.                 local humanoid = char:FindFirstChildOfClass("Humanoid")
  1089.                 if humanoid then
  1090.                     humanoid:TakeDamage(humanoid.MaxHealth)
  1091.                 end
  1092.             end
  1093.         end
  1094.     end)
  1095.  
  1096. end
  1097.  
  1098. --Push tool variables
  1099. local PUSH_FORCE = 30
  1100. local MAX_DISTANCE = 10
  1101. local COOL_PLAYER_UP = 2
  1102.  
  1103. --Handling client-side behavior from the server using knit inbuilt signals
  1104.  
  1105. --Handling some part of push tool in server when client calls this function
  1106. function MapHandlerService.Client:PushTool(player, origin, direction)
  1107.     print("Runned Server")
  1108.     local lastUsed = {}
  1109.     local Pushes = player:FindFirstChild("Pushes")
  1110.     if not Pushes or Pushes.Value <= 0 then return end
  1111.     if tick() - (lastUsed[player] or 0) < COOL_PLAYER_UP then return end
  1112.     lastUsed[player] = tick()
  1113.  
  1114.     local rayParams = RaycastParams.new()
  1115.     rayParams.FilterDescendantsInstances = {player.Character}
  1116.     rayParams.FilterType = Enum.RaycastFilterType.Blacklist
  1117.  
  1118.     local ray = workspace:Raycast(origin, direction * MAX_DISTANCE, rayParams)
  1119.     if ray and ray.Instance and ray.Instance:IsDescendantOf(workspace) then
  1120.         local hitChar = ray.Instance:FindFirstAncestorOfClass("Model")
  1121.         local hitPlayer = hitChar and game.Players:GetPlayerFromCharacter(hitChar)
  1122.         if hitPlayer and hitPlayer.Character and hitPlayer.Character:FindFirstChild("HumanoidRootPart") then
  1123.             Pushes.Value -= 1
  1124.             print("Player Got Hitted: ", hitPlayer)
  1125.             local hrp = hitPlayer.HumanoidRootPart
  1126.             local bodyVel = Instance.new("BodyVelocity")
  1127.             bodyVel.MaxForce = Vector3.new(1e5, 0, 1e5)
  1128.             bodyVel.Velocity = direction * PUSH_FORCE
  1129.             bodyVel.Parent = hrp
  1130.             game.Debris:AddItem(bodyVel, 0.2)
  1131.  
  1132.         else
  1133.             print("Hit player not found")
  1134.         end
  1135.     end
  1136. end
  1137.  
  1138. --functio to increment player extra life by 1
  1139. function MapHandlerService.Client:ExtraLifes(player:Player)
  1140.     local ExtraLifes = player:FindFirstChild("ExtraLifes")
  1141.     if ExtraLifes then
  1142.         ExtraLifes.Value += 1
  1143.     end
  1144. end
  1145.  
  1146.  
  1147. --function to give nametags to the players
  1148. function MapHandlerService.Client:GiveNameTags(player:Player, TextColor)
  1149.     local NameTag = ReplicatedStorage.Assets:FindFirstChild("nametagui")
  1150.     if NameTag then
  1151.  
  1152.         if player.Character:FindFirstChild("Head"):FindFirstChild(NameTag.Name) then
  1153.             player.Character:FindFirstChild("Head"):FindFirstChild(NameTag.Name):Destroy()
  1154.         end
  1155.  
  1156.         local CloneNameTag = NameTag:Clone()
  1157.         CloneNameTag.Parent = player.Character:FindFirstChild("Head")
  1158.         CloneNameTag.ntframe.username.Text = player.Name
  1159.         CloneNameTag.ntframe.username.UIGradient.Enabled = false
  1160.         CloneNameTag.ntframe.username.TextColor3 = TextColor
  1161.     end
  1162. end
  1163.  
  1164. --function to give less gravity boost to player
  1165. function MapHandlerService.Client:LessGravity(player:Player, argument)
  1166.     if argument == "IncreaseGravityValue" then
  1167.         local LessGravity = player:FindFirstChild("LessGravity")
  1168.         if LessGravity then
  1169.             LessGravity.Value += 1
  1170.         end
  1171.     else
  1172.         local LessGravity = player:FindFirstChild("LessGravity")
  1173.         if LessGravity then
  1174.             LessGravity.Value -= 1
  1175.         end
  1176.     end
  1177. end
  1178.  
  1179. --function to give brain rot to player character
  1180. function MapHandlerService.Client:WearBrainRot(player:Player, AssetId, argument, RewardTemplate)
  1181.     local success, info = pcall(function()
  1182.         return game:GetService("MarketplaceService"):GetProductInfo(AssetId)
  1183.     end)
  1184.     local success, info = pcall(function()
  1185.         if argument == "Wear" then
  1186.             print(info)
  1187.             if not success then return end
  1188.             if info.AssetTypeId == 8 then
  1189.                 for i, child in pairs(player.Character:GetDescendants()) do
  1190.                     if child:IsA("Accessory") then
  1191.                         if child.AccessoryType == Enum.AccessoryType.Hat then
  1192.                             child:Destroy()
  1193.                         end
  1194.                     end
  1195.                 end
  1196.                 self.UpdateRewardStatus:Fire(player, RewardTemplate)
  1197.  
  1198.                 local CloneAccessory = InsertService:LoadAsset(AssetId)
  1199.                 if CloneAccessory:IsA("Model") then
  1200.                     local Accessory = CloneAccessory:FindFirstChildOfClass("Accessory")
  1201.                     Accessory.Parent = player.Character
  1202.                     Accessory.AccessoryType = Enum.AccessoryType.Hat
  1203.                     CloneAccessory:Destroy()
  1204.                 end
  1205.             elseif  info.AssetTypeId == 46 then
  1206.                 for i, child in pairs(player.Character:GetDescendants()) do
  1207.                     if child:IsA("Accessory") then
  1208.                         if child.AccessoryType == Enum.AccessoryType.Neck then
  1209.                             child:Destroy()
  1210.                         end
  1211.                     end
  1212.                 end
  1213.                 local CloneAccessory = InsertService:LoadAsset(AssetId)
  1214.                 if CloneAccessory:IsA("Model") then
  1215.                     local Accessory = CloneAccessory:FindFirstChildOfClass("Accessory")
  1216.                     Accessory.Parent = player.Character
  1217.                     Accessory.AccessoryType = Enum.AccessoryType.Neck
  1218.                     CloneAccessory:Destroy()
  1219.                 end
  1220.             elseif  info.AssetTypeId == 42 then
  1221.                 for i, child in pairs(player.Character:GetDescendants()) do
  1222.                     if child:IsA("Accessory") then
  1223.                         if child.AccessoryType == Enum.AccessoryType.Face then
  1224.                             child:Destroy()
  1225.                         end
  1226.                     end
  1227.                 end
  1228.                 local CloneAccessory = InsertService:LoadAsset(AssetId)
  1229.                 if CloneAccessory:IsA("Model") then
  1230.                     local Accessory = CloneAccessory:FindFirstChildOfClass("Accessory")
  1231.                     Accessory.Parent = player.Character
  1232.                     Accessory.AccessoryType = Enum.AccessoryType.Hat
  1233.                     CloneAccessory:Destroy()
  1234.                 end
  1235.             elseif info.AssetTypeId == 67 then
  1236.                 for i, child in pairs(player.Character:GetDescendants()) do
  1237.                     if child:IsA("Accessory") then
  1238.                         if child.AccessoryType == Enum.AccessoryType.LeftShoe then
  1239.                             child:Destroy()
  1240.                         end
  1241.                     end
  1242.                 end
  1243.  
  1244.                 for i, child in pairs(player.Character:GetDescendants()) do
  1245.                     if child:IsA("MeshPart") or child:IsA("BasePart") or child:IsA("Decal") then
  1246.                         child.Transparency = 1
  1247.                     end
  1248.                 end
  1249.  
  1250.                 local CloneAccessory = InsertService:LoadAsset(AssetId)
  1251.                 if CloneAccessory:IsA("Model") then
  1252.                     local Accessory = CloneAccessory:FindFirstChildOfClass("Accessory")
  1253.                     Accessory.Parent = player.Character
  1254.                     Accessory.AccessoryType = Enum.AccessoryType.LeftShoe
  1255.                     CloneAccessory:Destroy()
  1256.                 end
  1257.             end
  1258.             print("Runned")
  1259.             return true
  1260.         else
  1261.             if info.AssetTypeId == 8 then
  1262.                 for i, child in pairs(player.Character:GetDescendants()) do
  1263.                     if child:IsA("Accessory") then
  1264.                         if child.AccessoryType == Enum.AccessoryType.Hat then
  1265.                             child:Destroy()
  1266.                         end
  1267.                     end
  1268.                 end
  1269.             elseif info.AssetTypeId == 46 then
  1270.                 for i, child in pairs(player.Character:GetDescendants()) do
  1271.                     if child:IsA("Accessory") then
  1272.                         if child.AccessoryType == Enum.AccessoryType.Neck then
  1273.                             child:Destroy()
  1274.                         end
  1275.                     end
  1276.                 end
  1277.             elseif info.AssetTypeId == 42 then
  1278.                 for i, child in pairs(player.Character:GetDescendants()) do
  1279.                     if child:IsA("Accessory") then
  1280.                         if child.AccessoryType == Enum.AccessoryType.Face then
  1281.                             child:Destroy()
  1282.                         end
  1283.                     end
  1284.                 end
  1285.             elseif info.AssetTypeId == 67 then
  1286.                 for i, child in pairs(player.Character:GetDescendants()) do
  1287.                     if child:IsA("Accessory") then
  1288.                         if child.AccessoryType == Enum.AccessoryType.LeftShoe then
  1289.                             child:Destroy()
  1290.                         end
  1291.                     end
  1292.                 end
  1293.  
  1294.                 for i, child in pairs(player.Character:GetDescendants()) do
  1295.                     if child.Name == "HumanoidRootPart" then continue end
  1296.                     if child:IsA("MeshPart") or child:IsA("BasePart") or child:IsA("Decal") then
  1297.                         child.Transparency = 0
  1298.                     end
  1299.                 end
  1300.             end
  1301.         end
  1302.         return true
  1303.     end)
  1304. end
  1305.  
  1306.  
  1307.  
  1308. --This is the first function that runs after Knit starts. It manages the core functionality of the entire module, including the round system, developer products/gamepasses, timer, and more
  1309. function MapHandlerService:KnitStart()
  1310.     self:DeveloperProductsHandler()
  1311.     repeat
  1312.         wait()
  1313.     until #game.Players:GetPlayers() > 0
  1314.  
  1315.     spawn(function()
  1316.         while wait() do
  1317.             for i, player in pairs(game.Players:GetPlayers()) do
  1318.                 if player:WaitForChild("PlayerSelectedMode").Value ~= "Easy" then continue end
  1319.                 self.Client.MusicEvent:Fire(player, "Play")
  1320.             end
  1321.             for i = 20, 0, -1 do
  1322.                 if self:PlayersInEasyMode() == 0 then
  1323.                     repeat
  1324.                         wait(0.3)
  1325.                     until self:PlayersInEasyMode() > 0
  1326.                 end
  1327.                 wait(1)
  1328.                 print("Loop Running")
  1329.                 for j, player in pairs(game.Players:GetPlayers()) do
  1330.                     spawn(function()
  1331.                         if player:WaitForChild("PlayerSelectedMode", math.huge).Value == "Easy" then
  1332.                             local Success, Pcall = pcall(function()
  1333.                                 local RoundTimer = player.PlayerGui:WaitForChild("Timer"):WaitForChild("RoundTimer")
  1334.                                 if RoundTimer.Visible == false then RoundTimer.Visible = true end
  1335.                                 if RoundTimer then
  1336.                                     RoundTimer.Text = "Round Will Start In: "..i
  1337.                                 end
  1338.                                 if i == 0 then
  1339.                                     wait(1)
  1340.                                     RoundTimer.Visible = false
  1341.                                 end
  1342.                             end)
  1343.                         end
  1344.                     end)
  1345.                 end
  1346.             end
  1347.             for i, player in pairs(game.Players:GetPlayers()) do
  1348.                 if player:WaitForChild("PlayerSelectedMode").Value ~= "Easy" then continue end
  1349.                 self.Client.MusicEvent:Fire(player, "Stop")
  1350.             end
  1351.             warn("Runned Last")
  1352.             wait(1)
  1353.             self:RopeMap("Easy")
  1354.             repeat
  1355.                 wait()
  1356.             until #PlayerInEasyRopeGame == 0
  1357.             wait(1)
  1358.         end
  1359.     end)
  1360.  
  1361.  
  1362.     while wait() do
  1363.         for i, player in pairs(game.Players:GetPlayers()) do
  1364.             if player:WaitForChild("PlayerSelectedMode").Value ~= "Hard" then continue end
  1365.             self.Client.MusicEvent:Fire(player, "Play")
  1366.         end
  1367.  
  1368.         for i = 20, 0, -1 do
  1369.             if self:PlayersInHardMode() == 0 then
  1370.                 repeat
  1371.                     wait(0.3)
  1372.                 until self:PlayersInHardMode() > 0
  1373.             end
  1374.             wait(1)
  1375.             for j, player in pairs(game.Players:GetPlayers()) do
  1376.                 spawn(function()
  1377.                     if player:WaitForChild("PlayerSelectedMode", math.huge).Value == "Hard" then
  1378.                         local Success, Pcall = pcall(function()
  1379.                             local RoundTimer = player.PlayerGui:WaitForChild("Timer"):WaitForChild("RoundTimer")
  1380.                             if RoundTimer.Visible == false then RoundTimer.Visible = true end
  1381.                             if RoundTimer then
  1382.                                 RoundTimer.Text = "Round Will Start In: "..i
  1383.                             end
  1384.                             if i == 0 then
  1385.                                 wait(1)
  1386.                                 RoundTimer.Visible = false
  1387.                             end
  1388.                         end)
  1389.                     end
  1390.                 end)
  1391.             end
  1392.         end
  1393.         wait(1)
  1394.         for i, player in pairs(game.Players:GetPlayers()) do
  1395.             if player:WaitForChild("PlayerSelectedMode").Value ~= "Hard" then continue end
  1396.             self.Client.MusicEvent:Fire(player, "Stop")
  1397.         end
  1398.  
  1399.         self:RopeMap("Hard")
  1400.         repeat
  1401.             wait()
  1402.         until #PlayerInHardRopeGame == 0
  1403.         wait(1)
  1404.     end
  1405.  
  1406. end
  1407.  
  1408.  
  1409. return MapHandlerService
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement