Prompt GamePass From A Click Detector

Why shouldn’t you prompt purchases on the client? :face_with_raised_eyebrow: That’s such a waste to fire a remote event to the server just to prompt a gamepass purchase.

3 Likes

Well since he attached a server script to the clickdetector he doesnt need a remoteEvent since the click detector has a player argument that he can use

1 Like

You can use one remote with multiple arguments…

But a Remote is not really necessary in this case.

Ye but why? All he wants is to prompt a purchase. You don’t need any server checks for that. It’s a waste

2 Likes

Its just a purchase so its not really taking up much memory, it doesnt really make a difference

Still shouldnt prompt purchases from server

3 Likes

Does prompt in the server(without remotes) is worse than prompt in client side?

image

i.e giving the player something or verifying it

I highly suggest you shouldn’t just make posts without knowing what you’re talking about. Using PromptGamePassPurchase or any other form of prompting on the client is perfectly safe and is the correct way of doing it. If it was insecure Roblox wouldn’t let you call it from the client.

Please do not derail this conversation with meaningless posts.

2 Likes

Wait, is the LocalScript in the ClickDetector? If it is, LocalScripts can only run in the Backpack, PlayerScripts, and some other things.

I recommend putting your LocalScript in the StarterPlayerScripts and changing the code to this;

local MPS = game:GetService("MarketplaceService")
local gamepassId = 12894476
local clickDetector =  --put your ClickDetector path here
local function promptPurchase()
	local player = game.Players.LocalPlayer
	local hasPass = false
	local success, message = pcall(function()
		hasPass = MPS:UserOwnsGamePassAsync(player.UserId, gamepassId)
	end)
	if hasPass == true then
		print("u already have")
	else
		MPS:PromptGamePassPurchase(player,gamepassId)
	end
end
clickDetector.MouseClick:Connect(promptPurchase)

Otherwise, if it’s in a Script, you can use this because ClickDetectors pass players as an argument.

local MPS = game:GetService("MarketplaceService")
local gamepassId = 12894476
local function promptPurchase(player)
	local hasPass = false
	local success, message = pcall(function()
		hasPass = MPS:UserOwnsGamePassAsync(player.UserId, gamepassId)
	end)
	if hasPass == true then
		print("u already have")
	else
		MPS:PromptGamePassPurchase(player,gamepassId)
	end
end
script.Parent.MouseClick:Connect(promptPurchase)
3 Likes

Hey, @elvinfch9, your code shud be in a normal script, and here is the code
local MPS = game:GetService(“MarketplaceService”)
local gamepassId = 12894476
local function promptPurchase(player)
local hasPass = false
local success, message = pcall(function()
hasPass = MPS:UserOwnsGamePassAsync(player.UserId, gamepassId)
end)
if hasPass == true then
print(“u already have”)
else
MPS:PromptGamePassPurchase(player,gamepassId)
end
end
script.Parent.MouseClick:Connect(promptPurchase)

--// Services
local MarketPlace = game:GetService("MarketplaceService")

--// Varaibles 
local Part = script.Parent
local ClickDetector = script.Parent.ClickDetector

local Product = 12894476

ClickDetector.MouseClick:Connect(function(player)
	if MarketPlace:UserOwnsGamePassAsync(player.UserId, Product) == true then
		print("u already have")
	else
		MarketPlace:PromptGamePassPurchase(player, Product)
	end
end)

Not gonna work. This would print “Cannot print Instance” or whatever since you’re printing a literal player, not their name. The Script would also not continue as it would break at the error.

1 Like

my bad, I forgot to delete that!

1 Like

I wanted do give you my script i made year ago but looks like it doesn’t work.
Maybe it’s just broken.

? no I just made the player player…