Hello. I need some help with my Checkpoint system.
Basically, I have made an obby game with a checkpoint system in it. When it was first made, it was working fine until today when I realised that when players got to a new stage, their stage number on the server leaderboard doesn’t change and stays the same. If you touch the next stage’s checkpoint, you still respawn at your latest checkpoint, it just doesn’t show on the server leaderboard.
I have no idea what I’ve done. It was working perfectly before. I don’t remember changing any parts of the script. Maybe I have added something else which made the error happen.
Here’s my checkpoint script.
local Players = game:GetService(“Players”)
local MarketplaceService = game:GetService(“MarketplaceService”)
local DataStoreService = game:GetService(“DataStoreService”)
local ObbyDataStore = DataStoreService:GetDataStore(“ObbyDataStore”)
local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local SkipStage = ReplicatedStorage:WaitForChild(“SkipStage”)
local ResetStage = ReplicatedStorage:WaitForChild(“ResetStage”)
local Checkpoints = workspace:WaitForChild(“Checkpoints”)
local inGameStartupPlayers = {}
local CurrentStage = {}
local TouchDb = {}
local ProductId = 1181478351
local function NewCharacter(player, char)
local TempCurrentStage = CurrentStage[player.UserId]
if TempCurrentStage ~= nil then
local TempCheckpoint = Checkpoints:FindFirstChild(TempCurrentStage)
if TempCheckpoint ~= nil then
repeat wait(0.1) until char.PrimaryPart ~= nil
char:SetPrimaryPartCFrame(CFrame.new(TempCheckpoint.Position + Vector3.new(0, 3, 0)) * CFrame.Angles(0, math.rad(TempCheckpoint.Orientation.Y) + math.rad(90), 0))
end
end
end
local function NewPlayer(player)
local success, stage = pcall(function()
return (ObbyDataStore:GetAsync(player.UserId)) or 1
end)
CurrentStage[player.UserId] = stage
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local Stage = Instance.new("IntValue", leaderstats)
Stage.Name = "Stage"
Stage.Value = stage
local TempChar = player.Character
if TempChar ~= nil then
NewCharacter(player, TempChar)
end
player.CharacterAdded:Connect(function(char)
NewCharacter(player, char)
end)
end
Players.PlayerAdded:Connect(function(player)
if inGameStartupPlayers[player] == nil then
NewPlayer(player)
end
end)
Players.PlayerRemoving:Connect(function(player)
local success = pcall(function()
ObbyDataStore:SetAsync(player.UserId, CurrentStage[player.UserId])
end)
CurrentStage[player.UserId] = nil
end)
SkipStage.OnServerInvoke = function(player)
local connection
local leaderstats = player:FindFirstChild(“leaderstats”)
if leaderstats ~= nil then
local Stage = leaderstats:FindFirstChild(“Stage”)
if Stage ~= nil then
if #Checkpoints:GetChildren() ~= Stage.Value then
local PurchaseResult = “Purchase Failed”
connection = MarketplaceService.PromptProductPurchaseFinished:Connect(function(userId, productId, purchased)
if player.UserId == userId and productId == ProductId then
if purchased == true then
PurchaseResult = “Success”
end
end
connection:Disconnect()
end)
MarketplaceService:PromptProductPurchase(player, ProductId)
repeat wait(0.1) until connection.Connected == false or Players:GetPlayerByUserId(player.UserId) == nil
return PurchaseResult
else
return “You have reached the highest stage!”
end
end
end
end
ResetStage.OnServerEvent:Connect(function(player)
CurrentStage[player.UserId] = 1
local TempLeaderstats = player:FindFirstChild(“leaderstats”)
if TempLeaderstats ~= nil then
local TempStage = TempLeaderstats:FindFirstChild(“Stage”)
if TempStage ~= nil then
TempStage.Value = 1
end
end
NewCharacter(player, player.Character)
end)
MarketplaceService.ProcessReceipt = function(recieptInfo)
if recieptInfo.ProductId == ProductId then
local player = Players:GetPlayerByUserId(recieptInfo.PlayerId)
if player ~= nil then
CurrentStage[player.UserId] = CurrentStage[player.UserId] + 1
local leaderstats = player:FindFirstChild(“leaderstats”)
if leaderstats ~= nil then
local Stage = leaderstats:FindFirstChild(“Stage”)
if Stage ~= nil then
Stage.Value = CurrentStage[player.UserId]
end
end
local TempChar = player.Character
if TempChar ~= nil then
NewCharacter(player, TempChar)
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
end
return Enum.ProductPurchaseDecision.NotProcessedYet
end
for i,v in pairs(Checkpoints:GetChildren()) do
local StageNum = tonumber(v.Name)
v.Touched:Connect(function(hit)
local char = hit.Parent
if char ~= nil then
local Humanoid = char:FindFirstChildOfClass(“Humanoid”)
if Humanoid ~= nil and Humanoid.Health > 0 then
local player = Players:GetPlayerFromCharacter(char)
if player ~= nil and (TouchDb[player.UserId] or 0) + 1 <= os.time() then
TouchDb[player.UserId] = os.time()
local TempCurrentStage = CurrentStage[player.UserId]
if TempCurrentStage == StageNum - 1 then
CurrentStage[player.UserId] = StageNum
local TempLeaderstats = player:FindFirstChild(“leaderstats”)
if TempLeaderstats ~= nil then
local TempStage = TempLeaderstats:FindFirstChild(“Stage”)
if TempStage ~= nil then
TempStage.Value = StageNum
end
end
end
end
end
end
end)
end
inGameStartupPlayers = Players:GetPlayers()
for i,v in pairs(inGameStartupPlayers) do
spawn(function()
NewPlayer(v)
end)
end
game:BindToClose(function()
for i,v in pairs(Players:GetPlayers()) do
ObbyDataStore:SetAsync(v.UserId, CurrentStage[v.UserId])
end
wait(1)
end)
inGameStartupPlayers = {}
Also, I have a skip stage button which, if you bought the developer product, you can skip a stage. It was also working fine but today it’s also broken. When I click the skip stage button, the developer product doesn’t show up. Here’s what I mean.
Here’s another video showing my leaderboard problem.
Here’s my skip stage script.
local TextButton = script.Parent
local Checkpoints = workspace:WaitForChild(“Checkpoints”)
local Players = game:GetService(“Players”)
local player = Players.LocalPlayer
local StageLeaderstat = player:WaitForChild(“leaderstats”):WaitForChild(“Stage”) — Line Six
local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local SkipStage = ReplicatedStorage:WaitForChild(“SkipStage”)
TextButton.MouseButton1Click:Connect(function()
if TextButton.Text == “Skip Stage ” then
if #Checkpoints:GetChildren() ~= StageLeaderstat.Value then
TextButton.Text = “Purchasing…”
local Response = SkipStage:InvokeServer()
TextButton.Text = Response
else
TextButton.Text = “You have reached the highest stage!”
end
wait(2)
TextButton.Text = “Skip Stage ”
end
end)
Another thing, when I test my game, in the output, it says:
'Infinite yield possible on ‘Players.monsterbu99.leaderstats:WaitForChild(“Stage”)’
When I click on the popup, it brings me to line 6 of my skip stage script. Does it have anything to do with that?
Please help me, I’m a beginner scripter and I do not know how to fix this. If you do know, please reply. Thank you for your time.