Issues with checkpoint and skip stage script

Evertime I test the game it spawns me on checkpoint 2 now and on the leaderboard it displays that I am on stage 0. Also the only checkpoint that spawns me when I die is checkpoint 2. My world spawn isn’t there and I haven’t changed the checkpoint’s name to 0 its still 2.

Error 1: ServerScriptService.CheckpointScript:23 - attempt to perform arithmetic (sub) on string and number This error occurs because you’re trying to perform arithmetic operations on a string and a number in the line if PlayerHit.leaderstats:FindFirstChild("Stage").Value == Checkpoint.Name - 1 then.

To fix this issue, convert the checkpoint name to a number before performing arithmetic operations. You can achieve this by using tonumber(Checkpoint.Name).

Here’s the corrected line:

if PlayerHit.leaderstats:FindFirstChild("Stage").Value == tonumber(Checkpoint.Name) - 1 then

Error 2: ServerScriptService.CheckpointScript:37 - attempt to index nil with ‘CFrame’ This error occurs because you’re trying to access the CFrame property of a checkpoint using CheckpointFolder:FindFirstChild(Stage.Value).CFrame, but the FindFirstChild function might return nil if there is no checkpoint with the specified name.

To address this issue, make sure that the checkpoint exists before attempting to access its properties.

Here’s the corrected line:

local specificCheckpoint = CheckpointsFolder:FindFirstChild(tostring(Stage.Value))
if specificCheckpoint then
    HumanoidRootPart.CFrame = specificCheckpoint.CFrame + Vector3.new(0, 2, 0)
end

By making these adjustments, you should be able to resolve the errors you’re encountering in your checkpoint script. Make sure to test the changes thoroughly to ensure that the script functions as expected.

1 Like

Thank you so much the checkpoints work finally! Do you have any idea what could be the issue in skip stage script though? It doesn’t work still.

Skip Stage:

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game.Players
local Your_Product_ID = 16231369024

MarketplaceService.ProcessReceipt = function(receiptInfo)
	local currency = "Stage"

	for _, player in ipairs(Players:GetPlayers()) do
		if player.UserId == receiptInfo.PlayerId then
			if receiptInfo.ProductId == Your_Product_ID then
				player.leaderstats[currency].Value += 1
				player.Character.Humanoid.Health = 0
			end
		end
	end

	return Enum.ProductPurchaseDecision.PurchaseGranted
end

1 Like

For some reason that doesn’t work either.

why dont you just use a simpler method: PromptProductPurchaseFinished

local mps = game:GetService("MarketplaceService")
local productId = 1623136902

mps.PromptProductPurchaseFinished:Connect(function(playerId, ProductId, purchased)
    if productId ~= ProductId or not purchased then return end
    local player = game.Players:GetPlayerByUserId(playerId)
    if player then
        player.leaderstats.Stage.Value += 1
        player:LoadCharacter()
    end
end)
1 Like

I finally found the issue and I am so sorry it was literally the dumbest one ever. I accidentally added an extra number to the product id there shouldn’t be a 4 in the end. Thanks for the help!

1 Like

For some reason it also plays the sound effect if an other player touches the checkpoint. How could I change the sound effect to play only local?

I’ve exactly answered that days ago, giving the proper credit is a must, but it’s okay… At least the topic is solved.

Thank you for solving the ServerScriptService.CheckpointScript:23 - attempt to perform arithmetic (sub) on string and number error. :slight_smile:

There’s no problem, I’m glad your scripts work :smile:.
I also solved your CFrame error by converting it into strings, there’s no need to check if the CFrame exists because the event triggering the function was the checkpoint. The condition would be useful if you don’t put your checkpoint inside the CheckPointFolder. Everything was in my last code correction post.
Y’all have a great day,
SnakperFR

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.