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

How do I make a button script that fires to a remote event when someone owns a gamepass?

I've recently made a project for myself to make a ranking system for a group of mine. I came across this issue today when testing the gui, I've tried multiple solutions that I have come up with, but all seem to not work.

Script for the local script

local ID = 7771902
local Remote = game.ReplicatedStorage.MainEvent
local plr = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
	if game:GetService("MarketplaceService"):PlayerOwnsAsset(plr, ID) then
		Remote:FireServer("dep")
	else
		game:GetService("MarketplaceService"):PromptGamePassPurchase(plr, ID)
	end
end)

Script for the server script (to test if it fired, I made print statements to print out what it fires)

local Remote = game.ReplicatedStorage.MainEvent
Remote.OnServerEvent:Connect(function(user, checker)
	print(user)
	print(checker)
end)

1 answer

Nvm, got help.

local ID = 7771902
local Remote = game.ReplicatedStorage.MainEvent
local plr = game.Players.LocalPlayer.UserId

script.Parent.MouseButton1Click:Connect(function()
    if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(plr, ID) then
        Remote:FireServer("dep")
    else
        game:GetService("MarketplaceService"):PromptGamePassPurchase(plr, ID)
    end
end)

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