Help with skip stage button

I’m having trouble with a skip stage button not sure why its not working I made a kill all button with the same script just different Id’s here is my local script in the textbutton

local plr = game.Players.LocalPlayer
local market = game:GetService("MarketplaceService")

local skipID = 1619494366

script.Parent.MouseButton1Click:Connect(function()
	market:PromptProductPurchase(plr, skipID)
end)

here is the script in the serverscriptservice

local players = game:GetService("Players")
local marketplace = game:GetService("MarketplaceService")

local skipID = 1619494366

marketplace.ProcessReceipt = function(receiptinfo)
	local plr = players:GetPlayerByUserId(receiptinfo.PlayerId)
	if not plr then
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
	if receiptinfo.ProductId == skipID then
		plr.leaderstats.Stage.Value += 1
	end
	return Enum.ProductPurchaseDecision.PurchaseGranted
end

not sure why its not working any help would be appreciated

what’s the issue? the value is not increasing?
the value increasing but not skipping player to another stage?

try the promtproductpurchasefinished then reply if it worked

its not increasing but it worked while ago then all the sudden it broke so idk what’s going on

The script is completelly fine…
Maybe there is another script that is causing the issue. Are there any errors or warnings in the console?

It would be great if you provide us also the kill script and the image of the toolbox where the button, the LocalScript and the ServerScript are stored so we can be able to help you :slight_smile:

The issue can be in the LocalScript itself if its parent is another button or is disabled. The same for the ServerScript

is the issue with the player not teleporting upon purchase?

because all you’re doing right now is increasing their stage number.

Are there multiple types of skip stage buttons in your game? I have noticed that depending on how you run the skip button, it can cause certain skip buttons to stop working.

2 Likes

this Is exactly the problem I made this exact script and tweaked it for skip stage button and my kill all button so how would I fix this?

1 Like

Can you show me the script for the kill all button?

1 Like
local players = game:GetService("Players")
local marketplace = game:GetService("MarketplaceService")

local skipID = 1804973481

marketplace.ProcessReceipt = function(receiptinfo)
	local plr = players:GetPlayerByUserId(receiptinfo.PlayerId)
	if not plr then
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
	if receiptinfo.ProductId == skipID then
		for i, v in pairs(game.Workspace:GetChildren()) do
			if v:FindFirstChild("Humanoid") then
				v.Humanoid.Health = 0
			end
		end
	end
	return Enum.ProductPurchaseDecision.PurchaseGranted
end

the id is not the same in the actual game just in that I used the same id but in game its not the samestrong text

Does the kill all button still work?

well when one works the other one doesn’t

Yeah, that was the same problem that I had in my game, let me look at them, and I’ll see if I can find a solution.

ok thank you
so very much also if u don’t mind I have a dif game that has throwable dynamite and I wanna track kills but how can’t figure it out

Since you use .ProcessReceipt twice, once in each script, they are going to conflict with each other. Instead, I would combine the two scripts together like this:

local players = game:GetService("Players")
local marketplace = game:GetService("MarketplaceService")

local skipID = 1804973481
local killAllID = 1619494366

marketplace.ProcessReceipt = function(receiptInfo)
	local player = players:GetPlayerByUserId(receiptInfo.PlayerId)
	if not player then
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
	
	if receiptInfo.ProductId == skipID then
		-- Handle skipping stage logic
		for _, part in ipairs(game.Workspace:GetChildren()) do
			if part:FindFirstChild("Humanoid") then
				part.Humanoid.Health = 0
			end
		end
	elseif receiptInfo.ProductId == killAllID then
		-- Handle killing all players logic
		for _, otherPlayer in ipairs(players:GetPlayers()) do
			if otherPlayer ~= player then
				local humanoid = otherPlayer.Character and otherPlayer.Character:FindFirstChild("Humanoid")
				if humanoid then
					humanoid.Health = 0
				end
			end
		end
	end
	
	return Enum.ProductPurchaseDecision.PurchaseGranted
end

I haven’t tested this out, so let me know if it works.

ok thanks ill try this looks promising

If you want to track kills, you are going to have to set up a datastore, with kills as your thing being tracked.

yooo it works tysm but in the dynamite thing how would I give the player the kill bc u throw it at them not hit them so idk how I would do that

You would have to set up a function within the datastore so that every time the player is killed, there kills go up by 1.

I am not able to test this at the moment, but you could try something like this, and build off of it if necessary:

-- Assume this is a Script in ServerScriptService

-- Load the DataStore service
local DataStoreService = game:GetService("DataStoreService")
local killsDataStore = DataStoreService:GetDataStore("PlayerKills")

-- Function to update player kills
local function updateKills(player)
    local playerId = player.UserId
    local key = "kills_" .. playerId
    
    local success, currentKills = pcall(function()
        return killsDataStore:GetAsync(key)
    end)
    
    if success then
        currentKills = currentKills or 0
        currentKills = currentKills + 1
        
        killsDataStore:SetAsync(key, currentKills)
    else
        warn("Failed to update kills for player " .. player.Name)
    end
end

-- Connect the updateKills function to a kill event
game.Players.PlayerKilled:Connect(function(victim, killer)
    if killer and killer:IsA("Player") then
        updateKills(killer)
    end
end)

-- Function to get the leaderboard data
local function getLeaderboard()
    local leaderboard = {}
    
    -- Get all player data from the DataStore
    local success, playerData = pcall(function()
        return killsDataStore:GetSortedAsync(false, 10) -- Get top 10 players by kills
    end)
    
    if success then
        for i, entry in ipairs(playerData) do
            leaderboard[i] = {
                player = game.Players:GetNameFromUserIdAsync(entry.key:split("_")[2]),
                kills = entry.value
            }
        end
    else
        warn("Failed to fetch leaderboard data")
    end
    
    return leaderboard
end

-- Example usage:
local leaderboard = getLeaderboard()
for i, entry in ipairs(leaderboard) do
    print(i .. ". " .. entry.player .. ": " .. entry.kills .. " kills")
end