Good afternoon, I need help with a script please. I’m still new to scripting, but I finally managed to make a skip stage button in my obby.
However, there’s an issue. Once I get to the last stage, if I skip again, I get stuck in an endless loop of dying. I understand why that happens, I just need help adding some functionality to prevent it from happening. (Maybe a temporary disable button?)
I will add my scripts in, thanks in advance.
This script is in ServerScriptService
MarketPlaceService = game:GetService("MarketplaceService")
MarketPlaceService.ProcessReceipt = function(receiptInfo)
local players = game.Players:GetPlayers()
local node = "Node"
local done = 0
for i = 1, #players do
if players[i].UserId == receiptInfo.PlayerId then
if receiptInfo.ProductId == 1109847551 and done == 0 then
done = 1
players[i].leaderstats[node].Value = players[i].leaderstats[node].Value + 1
players[i].Character.Humanoid.Health = 0
done = 0
end
end
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
And this script is behind my gui button
local productId = 1109847551 -- Change if needed
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Up:Connect(function()
game:GetService("MarketplaceService"):PromptProductPurchase(player, productId)
end)
Why are you using integers instead of boolean for done?
You should add an if statement that disables the button once the player reaches the last stage.
local Players = game:GetService("Players")
local MarketPlaceService = game:GetService("MarketplaceService")
MarketPlaceService.ProcessReceipt = function(receiptInfo)
local node = "Node"
for _, player : Player in ipairs(Players:GetPlayers()) do
if player.UserId == receiptInfo.PlayerId then
if receiptInfo.ProductId == 1109847551 then
if player.leaderstats[node] and not player.leaderstats[node].Value == MAX_VAL then -- Replace MAX_VAL with ur max stage (number)
player.leaderstats[node].Value += 1
player.Character.Humanoid.Health = 0
return Enum.ProductPurchaseDecision.PurchaseGranted
else
return false
end
end
end
end
return false
end