Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago
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
0
It is line 14 where the problem is itshydro7 1 — 4y
0
You can't change values on the client. uhi_o 417 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

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.

Ad

Answer this question