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

When I fire an event that prompts the user to buy an item after buying an item, it's nil, help?

Asked by
Ap_inity 112
6 years ago

Everytime I try to fire an event from a script then I call that event to prompt a user to buy an item once they bought an item, it always comes up with this error "Argument 2 missing or nil".

Here are my scripts:

ServerScriptService>PurchaseModelHandler

local folder = game.ReplicatedStorage.PurchasedModels
local player = game.Players.LocalPlayer

local counterid = 1272040120
local lampid = 1272039316

folder.Counter.OnClientEvent:connect(function(player)
    wait(3)
    game:GetService("MarketplaceService"):PromptPurchase(counterid, player)
end)

folder.Lamp.OnClientEvent:connect(function(player)
    wait(3)
    game:GetService("MarketplaceService"):PromptPurchase(lampid, player)
end)

ServerScriptService>PurchaseHandler

local marketServ = game:GetService("MarketplaceService")
local folder = game.ReplicatedStorage.PurchasedModels

local modelBuy1 = 126893799 -- Counter
local modelBuy2 = 126893609 -- Lamp

marketServ.ProcessReceipt = function(receiptInfo)
    for i, player in ipairs(game.Players:GetChildren()) do
        if player.userId == receiptInfo.PlayerId then
            if receiptInfo.ProductId == modelBuy1 then
                folder.Counter:FireClient(player)
            elseif receiptInfo.ProductId == modelBuy2 then
                folder.Lamp:FireClient(player)
            end
        end
    end
    return Enum.ProductPurchaseDecision.PurchaseGranted
end

Here are all my events: https://gyazo.com/65d345303b49752a37bd5fa81906c3ad

I've tried: RemoveEvents, BindableFunctions, BindableEvents, RemoteFunctions, all came up either: "Argument 2 missing or nil" or an error about ":OnClientInvoke()" or ":OnServerInvoke()".

Please help!

1 answer

Log in to vote
0
Answered by
mattscy 3725 Moderation Voter Community Moderator
6 years ago

When using FireClient, the first argument is used to determine which player's client you want to fire the event on (it will be fired for whichever player you use as that argument). However, when that client receives that event, the first player argument is not transferred, which is why it becomes nil. Instead of using this argument, you should just use

game.Players.LocalPlayer

to get the player from a local script.

Also, you may want to look into using FireAllClients instead of firing separate events for all the players.

Ad

Answer this question