Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

I thought this script works but.... it doesn't?

I bought it and I wasn't awarded a point. I don't know what's wrong.

GUI Script: local productId = 20752460
local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:connect(function() --DONT CHANGE THIS Game:GetService("MarketplaceService"):PromptProductPurchase(player, productId) end)

Leaderboard Script: game.Players.ChildAdded:connect(onPlayerEntered)

function onPlayerEntered(newPlayer) local stats = Instance.new("IntValue") stats.Name = "leaderstats"

local cash = Instance.new("IntValue")
cash.Name = "Immunity"
cash.Value = 0 

cash.Parent = stats
stats.Parent = newPlayer

end

game.Players.ChildAdded:connect(onPlayerEntered)

StatDataPersistence: function saveScore(player, score) player:SaveNumber("Immunity", score) -- rename "Ingredients" with your currency/statistic name... end

function loadScore(player, clickCounter)

local score = player:LoadNumber("Immunity") -- rename "Ingredients" with your currency/statistic name...

if score ~= 0 then
	clickCounter.Value = score
else
	print("Nothing to load/score was 0")
end

end

function onPlayerEntered(newPlayer) wait() local clicks = Instance.new("IntValue") clicks.Name = "Immunity" clicks.Value = 0

	local leaderstats = Instance.new("IntValue")
	leaderstats.Name = "leaderstats"

	leaderstats.Parent = newPlayer
	clicks.Parent = leaderstats

	newPlayer:WaitForDataReady()

	loadScore(newPlayer, clicks)

end

function onPlayerRemoving(player) print("Attempting to save score for " .. player.Name) local clicks = player:FindFirstChild("leaderstats"):FindFirstChild("Immunity") if (clicks ~= nil) then saveScore(player, clicks.Value) end end

game.Players.PlayerAdded:connect(onPlayerEntered) game.Players.PlayerRemoving:connect(onPlayerRemoving)

1 comment

0

Please put all you code in a code block.

1 answer

For the purchase to work, you need to create a Script in Workspace or ServerScriptService with the following code in it:

local ImmunityId = 20752460

Game:GetService("MarketplaceService").ProcessReceipt = function(receiptInfo) 
	for _, player in ipairs(game.Players:GetPlayers()) do
		if player.userId == receiptInfo.PlayerId then
		   if receiptInfo.ProductId == ImmunityId then
				player.leaderstats.Immunity.Value = player.leaderstats.Immunity.Value + 1
				return Enum.ProductPurchaseDecision.PurchaseGranted
			end
		end	
	end
end

This discussion is preserved as it was. New answers, comments, and votes are closed.