I keep getting an error for my Dev Product

So, I’m making a dev product where, when you buy it, it kicks the player. But I keep getting an error saying, ServerScriptService.Test:6: attempt to index nil with ‘Kick’

Here’s the code:
local MPS = game:GetService(“MarketplaceService”)

local player = game.Players.LocalPlayer

MPS.ProcessReceipt = function(receiptInfo)

if receiptInfo.ProductId == REDACTED then

player:Kick()

end

return Enum.ProductPurchaseDecision.PurchaseGranted

end

Is this a script or a local script

1 Like

I would guess its a LocalScript. I don’t see the point for this DevProduct right now anyways.

It says that the player doesn’t exist yet, or didn’t load. Meaning you either are using a server script ( Which would make the game.Players.Localplayer not work) or the player doesn’t have time to load.

The code should be in a script

Oh, the point of this dev product is just for testing purposes for what I’m actually trying to make.

It is a script. Not a local one.

You cannot use game.Players.LocalPlayer in a ServerScript.

Then what do I use to define the player?

You need to reference your player in a different way. Assuming you’re using a TextButton (or ImageButton) to purchase this DevProduct, you could fire a RemoteEvent from a LocalScript then pick it up on the server:

-- LocalScript inside of a TextButton or ImageButton

local RemoteEvent = -- path to your RemoteEvent

script.Parent.MouseButton1Click:Connect(function()
    RemoteEvent:FireServer()
end)
-- ServerScript in ServerScriptService

local RemoteEvent = -- path to your RemoteEvent

RemoteEvent.OnServerEvent:Connect(function(player) -- here is your player
    -- rest of your code
end)

It didn’t work unfortunately. :confused:

Try this code instead. Put this code on a server script by the way and prompt the dev product purchase on a local script. I think it should work.

MPS.ProcessReceipt = function(receiptInfo)
   if receiptInfo.ProductId == REDACTED then
       local plr = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
       plr:Kick()
   end
return Enum.ProductPurchaseDecision.PurchaseGranted;
end