Why is my ClickToPrompt to buy gamepass not working

So I copy pasted the other ClickToPromt part and the 1st version works but the 2nd one does not (btw this is about when you click the part a gamepass product popups.)


When you do an Instance.new, you don’t need to specify the path of the part, just do script.Parent.

You’re trying to call LocalPlayer in a server script… I believe this should all be in a LocalScript

Take out the following and it should work fine. Local Player doesn’t work in server scripts, but that’s okay because you can get the player from who clicked the clickdetector.

Player = game.Players.LocalPlayer

I agree with Aegians, you should use a LocalScript instead of a Server Script.

It’s because you have multiple children in workspace sharing the same name, which means your script can’t distinguish between them and just parents to the first one it finds.

If your script is parented to the part you intend on having the ClickDetector parented to, you can just parent the ClickDetector to script.Parent.

Also, LocalPlayer is not available in server scripts, but you are using the Player argument of ClickDetector.MouseClick (which is correct), as this tells a server script who clicked the part/model. You can remove the line referencing LocalPlayer.

Replace game.Workspace.ClickToPromptGamepass with script.Parent.

The reason the script didn’t work is because, there were multiple parts in the workspace with the name the script gave, and it’s likely that the script went for the wrong part. So, if you had just used script.Parent, it would’ve known to go for the part you intended.

Also, some people are saying put it in a LocalScript, this is incorrect, though. LocalScripts can only run if it’s a descendant of a PlayerGui, Backpack, PlayerScripts, or a character.

local ID = 13712532
local click = Instance.new("ClickDetector", game.Workspace.ClickToPromptGamepass)
local mps = game:GetService("MarketplaceService")
-- No need for player. It is specified in the function

click.MouseClick:Connect(function(plr)
 print("Should be working")
 mps:PromptGamePassPurchase(plr, ID)
end)

Let me know if that helps.

I don’t agree. LocalScripts can only run if it’s a descendant of a player (player for simplicity), or a player’s character.

local id = -- id here
local ms = game:GetService("MarketplaceService")
local c= Instance.new("ClickDetector")
c.Parent = script.Parent

c.MouseClick:Connect(function(p)
  ms:PromptGamePassPurchase(p,id)
end)