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

Why does the script works in studio but will not work in-game for GUI cash purchases?

I have it put into a local script and not sure what I am missing also put it in ScriptService, I really need help with this

game.StarterGui.ResetPlayerGuiOnSpawn = false
old_fog = game.Lighting.FogStart
local MarketplaceService = game:GetService("MarketplaceService")

function getPlayerFromId(id)
	for i,v in pairs(game.Players:GetChildren()) do
		if v.userId == id then
			return v
		end
	end
	return nil
end
 
MarketplaceService.ProcessReceipt = function(receiptInfo)
	local productId = receiptInfo.ProductId
	local playerId = receiptInfo.PlayerId
	local player = getPlayerFromId(playerId)
	local productName 
	
	if productId == 84313872 then
		local cashmoney = game.ServerStorage.MoneyStorage:FindFirstChild(player.Name)
			if cashmoney then
				cashmoney.Value = cashmoney.Value + 1000
			end
			
			
			
			elseif productId == 84313907 then
		local cashmoney = game.ServerStorage.MoneyStorage:FindFirstChild(player.Name)
			if cashmoney then
				cashmoney.Value = cashmoney.Value + 5000
			end
			
			
			
			elseif productId == 84314088 then
		local cashmoney = game.ServerStorage.MoneyStorage:FindFirstChild(player.Name)
			if cashmoney then
				cashmoney.Value = cashmoney.Value + 10000
			end
			
			
			
			elseif productId == 84313964 then
		local cashmoney = game.ServerStorage.MoneyStorage:FindFirstChild(player.Name)
			if cashmoney then
				cashmoney.Value = cashmoney.Value + 50000
			end
			
			
			
			elseif productId == 84314013 then
		local cashmoney = game.ServerStorage.MoneyStorage:FindFirstChild(player.Name)
			if cashmoney then
				cashmoney.Value = cashmoney.Value + 100000
			end
			
			
			
			elseif productId == 84315118 then
		local cashmoney = game.ServerStorage.MoneyStorage:FindFirstChild(player.Name)
			if cashmoney then
				cashmoney.Value = cashmoney.Value + 1000000
			end
			
			
			
			elseif productId == 84342316 then
		local cashmoney = game.ServerStorage.MoneyStorage:FindFirstChild(player.Name)
		local char = player.Character
		char.Humanoid.MaxHealth = char.Humanoid.MaxHealth + 25
		wait()
		char.Humanoid.Health = char.Humanoid.MaxHealth
		
		
		elseif productId == 84343085 then
		local char = player.Character
		if char then
			local human = char:FindFirstChild("Humanoid")
			if human then
				human.WalkSpeed = human.WalkSpeed + 25
			end
		end
	end
	return Enum.ProductPurchaseDecision.PurchaseGranted		
end

and the script I'm using for it

for i,v in pairs(script.Parent.Buttons:GetChildren()) do
	if v:isA("TextButton") then
		v.MouseButton1Click:connect(function()
			pcall(function()
				if v:FindFirstChild("Pass") then
					game.MarketplaceService:PromptPurchase(game.Players.LocalPlayer,tonumber(v.Name))
				else	
					game.MarketplaceService:PromptProductPurchase(game.Players.LocalPlayer,tonumber(v.Name))
				end
			end)
		end)
	end
end

1 answer

I figured it out, for some reason when I add more buttons than 7 the script no longer works for ROBLOX servers still don't know the reason why but solved.

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