Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why isn't my clickdetector gamepass shop working?

Asked by 5 years ago

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

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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)

Ad
Log in to vote
0
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

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!

Answer this question