The Buy Pad I Made Is Not Working

I tried to make a buy pad but it does not work

  1. I want it that when you touch a part it prompts to buy a game pass.

  2. It says something like “MarketplaceService:PromptGamePassPurchase() player should be of type Player, but is of type nil” and then stops the script.
    image

Here Is My Script If I Made A Mistake Can You Please Let Me Know Thanks.

local Player = game.Players.LocalPlayer
local Pad = script.Parent
local MarketPlaceService = game:GetService("MarketplaceService")
local PassId = 17693996

Pad.Touched:Connect(function(Touch)
	if Touch.Parent:FindFirstChild("Humanoid") then
		MarketPlaceService:PromptGamePassPurchase(Player, PassId)
	end
end)

Is your script Local or Server?

Thanks So Much I forgot About that. Lol thanks

The .Touched doesn’t pass a Player parameter. You haven’t defined Player either. Use this instead:

local Player = game.Players.LocalPlayer
local Pad = script.Parent
local MarketPlaceService = game:GetService("MarketplaceService")
local PassId = 17693996

Pad.Touched:Connect(function(Touch)
	if Touch.Parent:FindFirstChild("Humanoid") then
        local Player = game.Players:GetPlayerFromCharacter(Touch.Parent)
        if not Player then return end
		MarketPlaceService:PromptGamePassPurchase(Player, PassId)
	end
end)

Because you can’t get the Player using game.Players.LocalPlayer on a Server Script.

Ok but it has to be on a local script Right?

That wouldn’t work because from the looks of it, the localscript would be in workspace, and localscripts don’t work there, @THECOOLGENERATOR method would work, however, I’d do this

local Players = game:GetService("Players")
local MarketPlaceService = game:GetService("MarketplaceService")

local Pad = script.Parent

local PassId = 17693996

Pad.Touched:Connect(function(Touch)
    local Player = Players:GetPlayerFromCharacter(Touch.Parent)
    if not Player then 
		return 
	end
	MarketPlaceService:PromptGamePassPurchase(Player, PassId)
end)

Not really needed to check for the Humanoid if you’re checking if it belongs to a player

@CheckThisNow If you’d like to use the code I’ve shown, put it as a regular script in the part itself

1 Like

This should work on a Server script.

Well That works thank you. Have A Great Day.

Put solution on the answer that you find the most useful and effective.

1 Like

Forget it Thecoolgenerator’s own was wrong well sorry.

Sorry for the bump, but what do you mean that it was “wrong”?

game.Players.LocalPlayer

But you can only use that in a local script
No Hard Feelings?

I didn’t see that at the top of the script, sorry. But you can see that I never actually used the Player variable, and re-referenced it.

1 Like

No Problem Its Totally Fine. Ok?