Alright. I’m having some problems with the skip stage script and the saving data script. Soo, there 2 problems.
1)Everytime i buy the developer product, it’s +1 (ex, First buy skips “1” stage, Second buy skips “2” stages).
Then the second problem is this. Every time i join adds the times i bought the product (ex. i bought the pass 2 times it adds me 2 stage when i enter in the game).
SkipStage script inside severscript service:
local MPS = game:GetService("MarketplaceService")
MPS.ProcessReceipt = function(receiptInfo)
if receiptInfo.ProductId == 1062010432 then
local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
player.leaderstats.Stage.Value = player.leaderstats.Stage.Value + 1
local char = game.Workspace:FindFirstChild(player.Name)
local checkpoint = game.Workspace.Checkpoints:FindFirstChild(player.leaderstats.Stage.Value)
char:FindFirstChild("HumanoidRootPart").CFrame = CFrame.new(checkpoint.Position + Vector3.new(0,2,0), checkpoint.Position)
char:FindFirstChild("HumanoidRootPart").Orientation = Vector3.new(0,0,0)
return Enum.ProductPurchaseDecision.PurchaseGranted
end
end
Here’s the data store script inside serverscriptservice:
local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("myDataSore")
game.Players.PlayerAdded:Connect(function(Player)
local leaderstats = Instance.new("Folder", Player)
leaderstats.Name = "leaderstats"
leaderstats.Parent = Player
local Stage = Instance.new("IntValue")
Stage.Name = "Stage"
Stage.Value = 0
Stage.Parent = leaderstats
local data
local success, errormessagge = pcall(function()
data = myDataStore:GetAsync(Player.UserId.."-Stage")
end)
if success then
Stage.Value = data
else
print("There was an error whilst saving your data")
warn(errormessagge)
end
Player.CharacterAdded:Connect(function(Character)
repeat wait() until Player.Character ~= nil
local checkpoint = workspace.Checkpoints:FindFirstChild(Stage.Value)
Character:WaitForChild("HumanoidRootPart").CFrame = CFrame.new(checkpoint.Position + Vector3.new(0,2,0))
end)
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessagge = pcall(function()
myDataStore:SetAsync(player.UserId.."-Stage",player.leaderstats.Stage.Value)
end)
if success then
print("Player Data succesfully saved!")
else
print("There was an error when saving data")
warn(errormessagge)
end
end)
here’s the local script inside the button
script.Parent.MouseButton1Click:Connect(function()
local ms = game:GetService("MarketplaceService")
ms:PromptProductPurchase(game.Players.LocalPlayer, 1062010432)
end)