RXYSETTINGS

SummitSystem

Oct 31st, 2025 (edited)
1,399
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 12.18 KB | Source Code | 0 0
  1. local Players=game:GetService("Players")
  2. local ReplicatedStorage=game:GetService("ReplicatedStorage")
  3. local DataStoreService=game:GetService("DataStoreService")
  4. local HttpService=game:GetService("HttpService")
  5. local RunService=game:GetService("RunService")
  6.  
  7. local Config
  8. do
  9.     local ok,mod=pcall(function()return require(ReplicatedStorage:WaitForChild("Config"))end)
  10.     Config=(ok and type(mod)=="table") and mod or {
  11.         AllowCheckpointSkip=false,
  12.         SummitReward=1,
  13.         WebhookURL="",
  14.         OwnerUsernames={},
  15.         AdminUsernames={}
  16.     }
  17. end
  18.  
  19. local CheckpointData=DataStoreService:GetDataStore("SummitStoreV1")
  20. local touchCooldown={}
  21.  
  22. local function safeGet(key)
  23.     local tries=0
  24.     while tries<3 do
  25.         local ok,res=pcall(function()return CheckpointData:GetAsync(key)end)
  26.         if ok then return res end
  27.         tries+=1
  28.         task.wait(0.4)
  29.     end
  30.     return nil
  31. end
  32.  
  33. local function safeSet(key,value)
  34.     local tries=0
  35.     while tries<3 do
  36.         local ok=pcall(function()CheckpointData:SetAsync(key,value)end)
  37.         if ok then return true end
  38.         tries+=1
  39.         task.wait(0.4)
  40.     end
  41.     return false
  42. end
  43.  
  44. local function ensureRemote(name)
  45.     local r=ReplicatedStorage:FindFirstChild(name)
  46.     if r and r:IsA("RemoteEvent") then return r end
  47.     local new=Instance.new("RemoteEvent")
  48.     new.Name=name
  49.     new.Parent=ReplicatedStorage
  50.     return new
  51. end
  52.  
  53. local CP_Success=ensureRemote("CP_Success")
  54. local CP_Fail=ensureRemote("CP_Fail")
  55. local Summit_Success=ensureRemote("Summit_Success")
  56. local RunCommandEvent=ensureRemote("RunControlCommand")
  57.  
  58. local checkpointsFolder=workspace:FindFirstChild("Checkpoints")
  59. local summitPart=workspace:FindFirstChild("Summit")
  60. local fallFolder=workspace:FindFirstChild("FallParts")
  61. local startSpawnPart=workspace:FindFirstChild("StartSpawn")
  62.  
  63. if not checkpointsFolder then error("[CheckpointSystem] Missing Checkpoints") end
  64. if not summitPart then error("[CheckpointSystem] Missing Summit") end
  65.  
  66. local START_SPAWN_LOCATION=Vector3.new(0,5,0)
  67. if startSpawnPart and startSpawnPart:IsA("BasePart") then
  68.     START_SPAWN_LOCATION=startSpawnPart.Position+Vector3.new(0,5,0)
  69. end
  70.  
  71. local function isAdmin(player)
  72.     local name=(player.Name or tostring(player)):lower()
  73.     for _,v in ipairs(Config.OwnerUsernames or {}) do
  74.         if type(v)=="string" and name==v:lower() then return true end
  75.     end
  76.     for _,v in ipairs(Config.AdminUsernames or {}) do
  77.         if type(v)=="string" and name==v:lower() then return true end
  78.     end
  79.     return false
  80. end
  81.  
  82. Players.PlayerAdded:Connect(function(plr)
  83.     plr.CharacterAdded:Connect(function(char)
  84.         local ok,h=pcall(function()return char:WaitForChild("Humanoid",5)end)
  85.         if ok and h then h.DisplayDistanceType=Enum.HumanoidDisplayDistanceType.None end
  86.     end)
  87. end)
  88.  
  89. local checkpoints={}
  90. for _,c in ipairs(checkpointsFolder:GetChildren()) do
  91.     if c:IsA("BasePart") then table.insert(checkpoints,c) end
  92. end
  93.  
  94. local function getIndexFromName(name)
  95.     local n=name and name:match("%d+")
  96.     return n and tonumber(n) or math.huge
  97. end
  98.  
  99. table.sort(checkpoints,function(a,b)
  100.     return getIndexFromName(a.Name)<getIndexFromName(b.Name)
  101. end)
  102.  
  103. local COLOR_PASSED=Color3.fromRGB(0,255,0)
  104. local COLOR_UNPASSED=Color3.fromRGB(255,0,0)
  105.  
  106. local function teleportToCheckpoint(player,force)
  107.     local cpIndex=player:GetAttribute("Checkpoint") or 0
  108.     local pos
  109.     if force then
  110.         pos=(cpIndex>0 and checkpoints[cpIndex] and checkpoints[cpIndex].Position+Vector3.new(0,2,0))
  111.             or ((startSpawnPart and startSpawnPart:IsA("BasePart")) and startSpawnPart.Position+Vector3.new(0,5,0)
  112.             or START_SPAWN_LOCATION)
  113.     else
  114.         pos=(cpIndex>0 and checkpoints[cpIndex] and checkpoints[cpIndex].Position+Vector3.new(0,2,0))
  115.             or START_SPAWN_LOCATION
  116.     end
  117.     local char=player.Character
  118.     if not char then return end
  119.     local hrp=char:FindFirstChild("HumanoidRootPart")
  120.     if hrp then
  121.         local old=hrp.Anchored
  122.         hrp.Anchored=true
  123.         hrp.CFrame=CFrame.new(pos)
  124.         task.delay(0.2,function()if hrp then hrp.Anchored=old end end)
  125.     elseif char.PrimaryPart then
  126.         local pp=char.PrimaryPart
  127.         local old=pp.Anchored
  128.         pp.Anchored=true
  129.         char:SetPrimaryPartCFrame(CFrame.new(pos))
  130.         task.delay(0.2,function()if pp then pp.Anchored=old end end)
  131.     end
  132. end
  133.  
  134. local function setupPlayer(player)
  135.     local ls=player:FindFirstChild("leaderstats")
  136.     if not ls then
  137.         ls=Instance.new("Folder",player)
  138.         ls.Name="leaderstats"
  139.         local cp=Instance.new("IntValue",ls)
  140.         cp.Name="Checkpoint"
  141.         cp.Value=0
  142.         local sm=Instance.new("NumberValue",ls)
  143.         sm.Name="Summit"
  144.         sm.Value=0
  145.     end
  146.     local data=safeGet(player.UserId)
  147.     local lastCP=(data and data.LastCheckpoint) or 0
  148.     local totalSummit=(data and data.TotalSummit) or 0
  149.     ls.Checkpoint.Value=lastCP
  150.     ls.Summit.Value=totalSummit
  151.     player:SetAttribute("Checkpoint",lastCP)
  152.     player:SetAttribute("RunStartTime",os.time())
  153.     for i,cp in ipairs(checkpoints) do
  154.         cp.BrickColor=BrickColor.new(i<=lastCP and COLOR_PASSED or COLOR_UNPASSED)
  155.     end
  156.     player.CharacterAdded:Connect(function()
  157.         task.wait(0.1)
  158.         teleportToCheckpoint(player)
  159.     end)
  160. end
  161.  
  162. Players.PlayerAdded:Connect(setupPlayer)
  163. Players.PlayerRemoving:Connect(function(player)
  164.     if not player then return end
  165.     local summitVal=player:FindFirstChild("leaderstats") and player.leaderstats:FindFirstChild("Summit")
  166.     local cpVal=player:GetAttribute("Checkpoint")
  167.     if summitVal and cpVal~=nil then
  168.         pcall(function()
  169.             safeSet(player.UserId,{
  170.                 LastCheckpoint=cpVal,
  171.                 TotalSummit=summitVal.Value
  172.             })
  173.         end)
  174.     end
  175. end)
  176.  
  177. for i,cp in ipairs(checkpoints) do
  178.     if not cp then continue end
  179.     cp.Touched:Connect(function(hit)
  180.         local player=Players:GetPlayerFromCharacter(hit.Parent)
  181.         if not player then return end
  182.         if touchCooldown[player] then return end
  183.         touchCooldown[player]=true
  184.         task.delay(1,function() touchCooldown[player]=nil end)
  185.         local currentCP=player:GetAttribute("Checkpoint") or 0
  186.  
  187.         if not Config.AllowCheckpointSkip then
  188.             if i<=currentCP then return end
  189.             if i>currentCP+1 then
  190.                 CP_Fail:FireClient(player)
  191.                 return
  192.             end
  193.         else
  194.             if i<=currentCP then return end
  195.         end
  196.  
  197.         player:SetAttribute("Checkpoint",i)
  198.         if player:FindFirstChild("leaderstats") and player.leaderstats:FindFirstChild("Checkpoint") then
  199.             player.leaderstats.Checkpoint.Value=i
  200.         end
  201.         cp.BrickColor=BrickColor.new(COLOR_PASSED)
  202.  
  203.         CP_Success:FireClient(player,i)
  204.  
  205.         pcall(function()
  206.             safeSet(player.UserId,{
  207.                 LastCheckpoint=i,
  208.                 TotalSummit=player.leaderstats and player.leaderstats.Summit and player.leaderstats.Summit.Value or 0
  209.             })
  210.         end)
  211.     end)
  212. end
  213.  
  214. if summitPart then
  215.     summitPart.Touched:Connect(function(hit)
  216.         local player=Players:GetPlayerFromCharacter(hit.Parent)
  217.         if not player then return end
  218.         if touchCooldown[player] then return end
  219.         touchCooldown[player]=true
  220.         task.delay(1.2,function() touchCooldown[player]=nil end)
  221.  
  222.         local totalCP=#checkpoints
  223.         local currentCP=player:GetAttribute("Checkpoint") or 0
  224.         if currentCP<totalCP then
  225.             CP_Fail:FireClient(player)
  226.             return
  227.         end
  228.  
  229.         local startTime=player:GetAttribute("RunStartTime") or os.time()
  230.         local endTime=os.time()
  231.         local duration=math.max(0,endTime-startTime)
  232.         local h=math.floor(duration/3600)
  233.         local m=math.floor((duration%3600)/60)
  234.         local s=duration%60
  235.         local formattedTime=string.format("%02d:%02d:%02d",h,m,s)
  236.         local date=os.date("%Y-%m-%d %H:%M:%S",endTime)
  237.         local profileLink="https://www.roblox.com/users/"..player.UserId.."/profile"
  238.  
  239.         local summitStat=player.leaderstats and player.leaderstats:FindFirstChild("Summit")
  240.         if summitStat then summitStat.Value=summitStat.Value+(Config.SummitReward or 1) end
  241.  
  242.         player:SetAttribute("Checkpoint",0)
  243.         if player.leaderstats and player.leaderstats:FindFirstChild("Checkpoint") then
  244.             player.leaderstats.Checkpoint.Value=0
  245.         end
  246.  
  247.         player:SetAttribute("RunStartTime",os.time())
  248.  
  249.         for _,cp in ipairs(checkpoints) do
  250.             if cp and cp:IsA("BasePart") then
  251.                 cp.BrickColor=BrickColor.new(COLOR_UNPASSED)
  252.             end
  253.         end
  254.  
  255.         Summit_Success:FireClient(player)
  256.  
  257.         pcall(function()
  258.             safeSet(player.UserId,{
  259.                 LastCheckpoint=0,
  260.                 TotalSummit=summitStat and summitStat.Value or 0
  261.             })
  262.         end)
  263.  
  264.         local webhook=Config.WebhookURL
  265.         if webhook~="" then
  266.             task.spawn(function()
  267.                 local embed={
  268.                     username="Summit Logs",
  269.                     avatar_url="https://i.imgur.com/keJaZ9P.png",
  270.                     embeds={{
  271.                         title="🏔️ Summit Monitoring! by tt@sukitovone",
  272.                         color=16762624,
  273.                         fields={{
  274.                             {name="Username",value=player.Name,inline=true},
  275.                             {name="Display Name",value=player.DisplayName,inline=true},
  276.                             {name="User ID",value=tostring(player.UserId),inline=true},
  277.                             {name="Roblox Profile",value="["..player.Name.."]("..profileLink..")",inline=false},
  278.                             {name="Total Summits",value=tostring(summitStat and summitStat.Value or 0),inline=true},
  279.                             {name="Run Duration",value=formattedTime,inline=true},
  280.                             {name="Time Reached",value=date,inline=false}
  281.                         }}
  282.                     }}
  283.                 }
  284.                 local ok,err=pcall(function()
  285.                     HttpService:PostAsync(webhook,HttpService:JSONEncode(embed),Enum.HttpContentType.ApplicationJson)
  286.                 end)
  287.                 if not ok then warn("Webhook error:",err) end
  288.             end)
  289.         end
  290.     end)
  291. end
  292.  
  293. if fallFolder then
  294.     for _,part in ipairs(fallFolder:GetChildren()) do
  295.         if part:IsA("BasePart") then
  296.             part.Touched:Connect(function(hit)
  297.                 local player=Players:GetPlayerFromCharacter(hit.Parent)
  298.                 if player then teleportToCheckpoint(player,true) end
  299.             end)
  300.         end
  301.     end
  302. end
  303.  
  304. RunCommandEvent.OnServerEvent:Connect(function(player,command,targetName,amount)
  305.     if not isAdmin(player) then
  306.         RunCommandEvent:FireClient(player,"Notification","❌ Gagal: Bukan admin",Color3.fromRGB(255,0,0))
  307.         return
  308.     end
  309.     if command=="AdjustSummit" and type(amount)=="number" then
  310.         local target=Players:FindFirstChild(targetName)
  311.         if not target then
  312.             RunCommandEvent:FireClient(player,"Notification","⚠️ Pemain "..targetName.." tidak ditemukan",Color3.fromRGB(255,0,0))
  313.             return
  314.         end
  315.         local stat=target.leaderstats and target.leaderstats:FindFirstChild("Summit")
  316.         if stat then
  317.             stat.Value=stat.Value+amount
  318.             pcall(function()
  319.                 safeSet(target.UserId,{
  320.                     LastCheckpoint=target:GetAttribute("Checkpoint"),
  321.                     TotalSummit=stat.Value
  322.                 })
  323.             end)
  324.             local action=amount>=0 and "ditambahkan" or "dikurangi"
  325.             RunCommandEvent:FireClient(
  326.                 player,
  327.                 "Notification",
  328.                 string.format("✅ Summit %s %.1f untuk %s (Total: %.1f)",action,math.abs(amount),targetName,stat.Value),
  329.                 Color3.fromRGB(0,200,0)
  330.             )
  331.         else
  332.             RunCommandEvent:FireClient(player,"Notification","❌ Leaderstat 'Summit' tidak ditemukan",Color3.fromRGB(255,0,0))
  333.         end
  334.     end
  335. end)
  336.  
  337. print("[Checkpoint System Integrated Successfully! Fixed for Publish]")
Advertisement
Add Comment
Please, Sign In to add comment