Script Issues | Prompt Not Working

I’ve got an script which is supposed to popup purchase prompt when brick touched and grant the item after purchase is done (RemoteEvent).

For some reason, the purchase prompt is not popping up.
Any clue what’s wrong with my script?

This is a Script, not a LocalScript, located inside the brick:

wait(2)

function onTouch(hit)

local mps = game:GetService("MarketplaceService")
local gamepass_id = 7041868

script.Parent.Touched:connect(function()
local player = game.Players.LocalPlayer
mps:PromptGamePassPurchase(player, gamepass_id)
end)

mps.PromptGamePassPurchaseFinished:connect(function(player, id, purchased)
if id == gamepass_id and purchased then
game.ReplicatedStorage.Give3:FireServer()

end
end)
end

script.Parent.Touched:connect(onTouch)
local mps = game:GetService("MarketplaceService")
local gamepass_id = 7041868

script.Parent.Touched:connect(function(hit)
   if hit.Parent:FindFirstChild("Humanoid") then
      local plr = game.Players:FindFirstChild(hit.Parent.Name)
      mps:PromptGamePassPurchase(plr, gamepass_id)
      print("prompt") -- check if it sends prompt
   end
end)

mps.PromptGamePassPurchaseFinished:connect(function(player, id, purchased)
   if id == gamepass_id and purchased then
      game.ReplicatedStorage.Give3:FireServer()
      print("bought") -- check if it sends signal after buying
   end
end)

I didnt test it but it should work.

1 Like

Thank you so much dude! :smiley: It works.

1 Like