Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why isn't my clickdetector gamepass shop working?

I've been working on a gamepass shop gui but I scrapped it in favor of a shop using clickdetectors. I've used the wiki to research clickdetectors and gamepasses but I still can't get it to work. The idea is that when a player left clicks on the part with the clickdetector, it prompts the gamepass purchase. The following localscript is in the clickdetector:

local player = game.Players.LocalPlayer
local gamePassId = 5820057
script.Parent.MouseClick:Connect(function()
	game:GetService('MarketplaceService'):PromptGamePassPurchase(player, gamePassId)
end)

What am I doing wrong?

2 answers

The issue is that you're using a LocalScript in the workspace presumably. All you need to do is use this code in a server script. On the server, however, you cannot use LocalPlayer. Thankfully, MouseClick's parameter is the player who clicked.

--Server Script

local gamePassId = 5820057

script.Parent.MouseClick:Connect(function(player)
    game:GetService('MarketplaceService'):PromptGamePassPurchase(player, gamePassId)
end)

I believe ClickDetectors are meant to be handled with ServerScripts, yet this would cause an Issue as they're denied access to the Player because of FE regulations. Though if the Player was somehow provided and approved to the Script, this would allow access. This is possible because ClickDetectors return the Player who Clicked. Try rearranging your Script to this

local Part = workspace.Part
local GamepassId = 123456789
Part.ClickDetector.MouseClick:Connect(function(Player)
    game:GetService("MarketplaceService"):PromptGamePassPurchase(Player, Gamepassid)
end)

Hope this helps! if so don't forget to accept this answer!

This discussion is preserved as it was. New answers, comments, and votes are closed.