Tweak16

ROBLOX Scripting | Server Script | Skip Stage Checkpoints

Jan 23rd, 2021 (edited)
1,343
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --[[
  2. Made by Tweakified, Neonblox Games
  3. Video: https://www.youtube.com/watch?v=Yki2Y-IuNnA
  4. Client Script: https://pastebin.com/b3J3fjvC
  5.  
  6. Script Type: Regular Script
  7. Script Parent: ServerScriptService
  8. --]]
  9.  
  10. local Players = game:GetService("Players")
  11. local MarketplaceService = game:GetService("MarketplaceService")
  12. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  13. local SkipStage = ReplicatedStorage:WaitForChild("SkipStage")
  14.  
  15. local Checkpoints = workspace:WaitForChild("Checkpoints")
  16. local inGameStartupPlayers = {}
  17. local CurrentStage = {}
  18. local TouchDb = {}
  19.  
  20. local ProductId = 1135733177
  21.  
  22. local function NewCharacter(player, char)
  23.     local TempCurrentStage = CurrentStage[player.UserId]
  24.     if TempCurrentStage ~= nil then
  25.         local TempCheckpoint = Checkpoints:FindFirstChild(TempCurrentStage)
  26.         if TempCheckpoint ~= nil then
  27.             repeat wait(0.1) until char.PrimaryPart ~= nil
  28.             char:SetPrimaryPartCFrame(CFrame.new(TempCheckpoint.Position + Vector3.new(0, 3, 0)) * CFrame.Angles(0, math.rad(TempCheckpoint.Orientation.Y) + math.rad(90), 0))
  29.         end
  30.     end
  31. end
  32.  
  33. local function NewPlayer(player)
  34.     CurrentStage[player.UserId] = 1
  35.  
  36.     local leaderstats = Instance.new("Folder", player)
  37.     leaderstats.Name = "leaderstats"
  38.     local Stage = Instance.new("IntValue", leaderstats)
  39.     Stage.Name = "Stage"
  40.     Stage.Value = 1
  41.  
  42.     local TempChar = player.Character
  43.     if TempChar ~= nil then
  44.         NewCharacter(player, TempChar)
  45.     end
  46.     player.CharacterAdded:Connect(function(char)
  47.         NewCharacter(player, char)
  48.     end)
  49. end
  50.  
  51. Players.PlayerAdded:Connect(function(player)
  52.     if inGameStartupPlayers[player] == nil then
  53.         NewPlayer(player)
  54.     end
  55. end)
  56.  
  57. Players.PlayerRemoving:Connect(function(player)
  58.     CurrentStage[player.UserId] = nil
  59. end)
  60.  
  61. SkipStage.OnServerInvoke = function(player)
  62.     local connection
  63.     local leaderstats = player:FindFirstChild("leaderstats")
  64.     if leaderstats ~= nil then
  65.         local Stage = leaderstats:FindFirstChild("Stage")
  66.         if Stage ~= nil then
  67.             if #Checkpoints:GetChildren() ~= Stage.Value then
  68.                 local PurchaseResult = "Purchase Failed"
  69.                 connection = MarketplaceService.PromptProductPurchaseFinished:Connect(function(userId, productId, purchased)
  70.                     if player.UserId == userId and productId == ProductId then
  71.                         if purchased == true then
  72.                             PurchaseResult = "Success"
  73.                         end
  74.                     end
  75.                     connection:Disconnect()
  76.                 end)
  77.                 MarketplaceService:PromptProductPurchase(player, ProductId)
  78.                 repeat wait(0.1) until connection.Connected == false or Players:GetPlayerByUserId(player.UserId) == nil
  79.                 return PurchaseResult
  80.             else
  81.                 return "You have reached the highest stage!"
  82.             end
  83.         end
  84.     end
  85. end
  86.  
  87. MarketplaceService.ProcessReceipt = function(recieptInfo)
  88.     if recieptInfo.ProductId == ProductId then
  89.         local player = Players:GetPlayerByUserId(recieptInfo.PlayerId)
  90.         if player ~= nil then
  91.             CurrentStage[player.UserId] = CurrentStage[player.UserId] + 1
  92.             local leaderstats = player:FindFirstChild("leaderstats")
  93.             if leaderstats ~= nil then
  94.                 local Stage = leaderstats:FindFirstChild("Stage")
  95.                 if Stage ~= nil then
  96.                     Stage.Value = CurrentStage[player.UserId]
  97.                 end
  98.             end
  99.             local TempChar = player.Character
  100.             if TempChar ~= nil then
  101.                 NewCharacter(player, TempChar)
  102.             end
  103.             return Enum.ProductPurchaseDecision.PurchaseGranted
  104.         end
  105.     end
  106.     return Enum.ProductPurchaseDecision.NotProcessedYet
  107. end
  108.  
  109. for i,v in pairs(Checkpoints:GetChildren()) do
  110.     local StageNum = tonumber(v.Name)
  111.     v.Touched:Connect(function(hit)
  112.         local char = hit.Parent
  113.         if char ~= nil then
  114.             local Humanoid = char:FindFirstChildOfClass("Humanoid")
  115.             if Humanoid ~= nil and Humanoid.Health > 0 then
  116.                 local player = Players:GetPlayerFromCharacter(char)
  117.                 if player ~= nil and (TouchDb[player.UserId] or 0) + 1 <= os.time() then
  118.                     TouchDb[player.UserId] = os.time()
  119.                     local TempCurrentStage = CurrentStage[player.UserId]
  120.                     if TempCurrentStage == StageNum - 1 then
  121.                         CurrentStage[player.UserId] = StageNum
  122.                         local TempLeaderstats = player:FindFirstChild("leaderstats")
  123.                         if TempLeaderstats ~= nil then
  124.                             local TempStage = TempLeaderstats:FindFirstChild("Stage")
  125.                             if TempStage ~= nil then
  126.                                 TempStage.Value = StageNum
  127.                             end
  128.                         end
  129.                     end
  130.                 end
  131.             end
  132.         end
  133.     end)
  134. end
  135.  
  136. inGameStartupPlayers = Players:GetPlayers()
  137. for i,v in pairs(inGameStartupPlayers) do
  138.     spawn(function()
  139.         NewPlayer(v)
  140.     end)
  141. end
  142.  
  143. inGameStartupPlayers = {}
RAW Paste Data