local mps = game:GetService(“MarketplaceService”)
local product_id = 123456789 – Replace with your product ID
script.Parent.MouseButton1Click:Connect(function()
local player = game.Players.LocalPlayer
mps:PromptPurchase(player, product_id)
end)
mps.PromptPurchaseFinished:Connect(function(player, id, purchased)
if id == product_id and purchased then
game.ReplicatedStorage.Give:FireServer()
end
end)
Can you provide any logs/screenshots from the console? You have given basically no context. It looks like you copied this script from somewhere, please provide info on your problem. Off the bat, I don’t think 123456789 is a product id, replace that.
Also, you can’t prompt a purchase from a local script
LocalScript
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local promptPurchaseEvent = ReplicatedStorage:WaitForChild("PromptPurchaseEvent")
local product_id = 123456789 – this is def not a real product, replace this with your product id
script.Parent.MouseButton1Click:Connect(function()
promptPurchaseEvent:FireServer(product_id)
end)
ServerScript
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local mps = game:GetService("MarketplaceService")
local promptPurchaseEvent = ReplicatedStorage:WaitForChild("PromptPurchaseEvent")
local function onPromptPurchaseFinished(player, assetId, isPurchased)
if isPurchased then
-- Put your code for the "Give" remote event you had previously here.
end
end
promptPurchaseEvent.OnServerEvent:Connect(function(player, id)
mps:PromptPurchase(player, id)
end)
mps.PromptPurchaseFinished:Connect(onPromptPurchaseFinished)
The code should work.
Check your placements of your scripts, because LocalScripts are limited to where they can execute their code.
Also, you should be performing this check on the Server instead of the Client.
This this script is a regular Script, you cannot use LocalPlayer as the script does not run for a specific Player.