Script not working as intended

I’m trying to make it so if you trigger the prompt it will show up with a developer product. But it’s not doing anything, there isn’t any errors either. The script is in the proximity prompt.

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

local productID = 1262549913 

if script.Parent.Triggered then
	local function promptPurchase()
		local player = Players.LocalPlayer
		MarketplaceService:PromptProductPurchase(player, productID)
	end
end

You have to call the function:


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

local productID = 1262549913 

local function promptPurchase()
	local player = Players.LocalPlayer
	MarketplaceService:PromptProductPurchase(player, productID)
end

if script.Parent.Triggered then
    promptPurchase()
end

It’s saying in the output “MarketplaceService:PromptProductPurchase() player should be of type Player”

Is this a server or local script?

It’s a normal script. In the proximity prompt.

Okay well you can use LocalPlayer in a server script

Try this script:


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

local productID = 1262549913 

local function promptPurchase(player)
	MarketplaceService:PromptProductPurchase(player, productID)
end

script.Parent.Triggered:Connect(function(player)
    promptPurchase(player)
end

This is the only way it will work, even if the other script was a local script the function would fire because you don’t detect when the prompt gets triggered you only did it once, this way it will fire Everytime you trigger it

Triggered is an event of Proximity Prompt
You should connect a listener to it that calls your function

local function promptPurchase(player)
   MarketplaceService:PromptProductPurchase(player, productID)
end

script.Parent.Triggered:Connect(promptPurchase)

Triggered provides to the function called the player who triggered it as a parameter so all the info you need is right there already.

Aww just a tad too late :frowning: I blame the links.

1 Like

Should I put this in serverscriptservice?

for the proximity prompt to work the script (that was inside the proximity prompt) needs to be in starter gui

I would, but if you move it you will need to change your reference to the ProximityPrompt

local myPrompt = workspace.dilly.whopper.ProximityPrompt

...

myPrompt.Triggered:Connect(promptPurchase)

It keeps saying the same thing in every script I’ve tried so far. “MarketplaceService:PromptProductPurchase() player should be of type Player”

Did you replace everything in the script with what TSL gave you?
Or do you have extra lines of otherstuff?

I have done this now but it’s still saying in the output, “MarketplaceService:PromptProductPurchase() player should be of type Player”. I don’t know if it’s because I’m using a starterchacter.

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer

local productID = 1262549913 

local myPrompt = workspace.OneHundredCoins.Coins1.ProximityPrompt

local function promptPurchase(player)
	MarketplaceService:PromptProductPurchase(player, productID)
end
game.Workspace.OneHundredCoins.Coins1.ProximityPrompt.Triggered:Connect(promptPurchase)

remove

local Players = game:GetService("Players")
local player = Players.LocalPlayer

Did you leave an old script laying around?
The one you posted works for me. Even with the unneeded player at the top.

If you’re using a server script then you cant use the local player in it, I’m pretty sure the function is getting confused on what variable to use so it uses the local player one which you cant use, it will return nil.
Also, what do you mean by using the starter character? is this script parented under starter-character scripts? If so, put it under the prompt.

Try this script:

local MarketplaceService = game:GetService(“MarketplaceService”)

local productID = 1262549913

local myPrompt = workspace.OneHundredCoins.Coins1.ProximityPrompt

myPrompt.Triggered:Connect(function(plr)
MarketplaceService:PromptProductPurchase(plr, productID)
end)

2 Likes

I did the something really stupid, I had two proximity prompts because there’s two coins in the model so I was pressing the original one I was supposed to delete ages ago.

Lol surprised it took ten extra replies to get a solution that is basically the exact same as everything above.

Yes, I was just being an idiot lol