So this is a simple script I put together from different scripts but it does not work. I can’t seem to get it to detect the part so it counts as a stage and then make it stop once the player reaches the last part.
Here is the main script in ServerScriptService:
MarketplaceService = game:GetService("MarketplaceService")
MarketplaceService.ProcessReceipt = function(receiptInfo)
local players = game.Players:GetPlayers()
local currency = "Stage"
local var = 0
for i=1,#players do
if players[i].userId == receiptInfo.PlayerId then
if receiptInfo.ProductId == 1310141274 and var == 0 then
var = 1
players[i].leaderstats[currency].Value = players[i].leaderstats[currency].Value + 1
players[i].Character.Humanoid.Health = 0
var = 0
end
end
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
leaderstats:
game.Players.PlayerAdded:Connect(function(player)
local leaderstats= Instance.new("Folder")
leaderstats.Name= ("leaderstats")
leaderstats.Parent= player
local cash= Instance.new("IntValue")
cash.Name= ("Stage")
cash.Parent = leaderstats
cash.Value = 0
end)
And here is the dev product script:
local productId = 1310141274
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:connect(function()
game:GetService("MarketplaceService"):PromptProductPurchase(player, productId)
end)
MarketplaceService = game:GetService("MarketplaceService")
MarketplaceService.ProcessReceipt = function(receiptInfo)
local players = game.Players:GetPlayers()
local currency = "Stage"
local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
if receiptInfo.ProductId == 1310141274 and player then
player.leaderstats[currency].Value += 1
end
if not player then return Enum.ProductPurchaseDecision.NotProcessedYet end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
Also, I figure that the problem is right here
Roblox is very picky about capitals, so you probably needed to capitalize the u in UserId.
Okay! Thanks, the Gui is now adding a stage every time in the leaderstats but how do I make it so each part is a checkpoint adding a stage and that the Gui correlates with that?
Sorry for the very late reply, but you should probably have your own spawning system. EX:
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local stage = plr.leaderstats.Stage.Value
local spawn = workspace.Spawns["Stage"..stage]--just an example
local hrp = char:WaitForChild("HumanoidRootPart")
hrp.CFrame = CFrame.new(Spawn.Position + Vector3.new(0, char.Torso.Size.Y, 0))
end)
end)
local MarketPlaceService = game:GetService("MarketplaceService")
local Id = 1310141274
MarketPlaceService.PromptProductPurchaseFinished:Connect(function(PlayerUserId, ProductId, succes)
local Player = game:GetService("Players"):GetPlayerByUserId(PlayerUserId)
local leaderstats = Player:WaitForChild("leaderstats")
if ProductId == Id and succes == true then
leaderstats.Stage.Value += 1
Player:LoadCharacter()
end
end)