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

How do i fix: "Attempt to index nil with 'IntValue'"?

local MarketplaceService = game:GetService("MarketplaceService")
local plrs = game:GetService("Players")
local id = 985264450

local function processReceipt(recieptInfo)
	
	local plr = plrs:GetPlayerByUserId(recieptInfo.PlayerId)
	if not plr then
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
	
	if plr then
		
		game.Players.LocalPlayer.Gems.Value = game.Players.LocalPlayer.Gems.Value + 100
		
	end
	
	return Enum.ProductPurchaseDecision.PurchaseGranted
	
end

MarketplaceService.ProcessReceipt = processReceipt

2 comments

0

It is line 14 where the problem is

0

You can't change values on the client.

1 answer

✓ Accepted answer

Hello.

Problem

You used LocalPlayer in a ServerScript, which doesn't work because a ServerScript doesn't run on the client. Instead, it runs on a physical server.

Solution

Use the "plr" variable you made instead of LocalPlayer

Fixed Script:

local MarketplaceService = game:GetService("MarketplaceService")
local plrs = game:GetService("Players")
local id = 985264450

local function processReceipt(recieptInfo)

    local plr = plrs:GetPlayerByUserId(recieptInfo.PlayerId)
    if not plr then
        return Enum.ProductPurchaseDecision.NotProcessedYet
    end

    if plr then

        plr.Gems.Value = plr.Gems.Value + 100

    end

    return Enum.ProductPurchaseDecision.PurchaseGranted

end

MarketplaceService.ProcessReceipt = processReceipt

Please accept this answer if it helped. There's been a bug for new users that you have to go into incognito mode to accept an answer.

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