PromptPurchase Issue

On the 8th line is the problem.

local gamepass = game:GetService("GamePassService")
local market = game:GetService("MarketplaceService")
	
local part = script.Parent

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		market:PromptGamePassPurchase(game.Players, 4367427794)
			part.BrickColor = BrickColor.new("Lime green")
	end
end)

Console Error

MarketplaceService:PromptGamePassPurchase() player should be of type Player, but is of type Players

You gotta put something after game.Players, probably the name of the player

You’re putting the Players service, instead of a single player:

script.Parent.Touched:Connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if player then
		market:PromptGamePassPurchase(player, 4367427794)
	    part.BrickColor = BrickColor.new("Lime green")
	end
end)
2 Likes

I’ve tried player.

Unknown global 'player'

The name of the player should be hit’s Parent. You could put in game.Players:FindFirstChild(hit.Parent.Name)

Because you didn’t define player. Try the script I have provided

1 Like

Or just “player” the variable they set it to.

Both ways definitely work! I just don’t really like creating variables when they’ll only be used once. To me, it’s wasted memory, even if it is just a few bytes.

I understand your point; though in this situation he could be using it to “kill two birds with one stone.”

This script should work, just copy it. If you need reference; MarketplaceService | Documentation - Roblox Creator Hub.

It worked, thank you all!

script.Parent.Touched:Connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if player then
		market:PromptGamePassPurchase(player, 1057151)
	    part.BrickColor = BrickColor.new("Lime green")
	end
end)