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

Game pass detection not functioning correctly?

What it should do is fire a remote when the click detector is clicked, the click detector then makes sure the player has the gamepass and if they don't it prompts the purchase for it. Then the local script, when the remote is run will check again if the player has the gamepass(to stop exploiters from just firing the remote) But I get this error on line 11 of the server script:

12:08:15.831 - Unable to cast Instance to int64

Server:

local this = script.Parent
local CL = script.Parent.CL
local mp = game:GetService("GamePassService")
local remote = game.Lighting.OD
local mp2 = game:GetService("MarketplaceService")

CL.MouseClick:Connect(function(plr)
	if mp:PlayerHasPass(plr,5043985) then
		remote:FireClient(plr)
	else
		mp2:PromptGamePassPurchase(5043985,plr)
	end
end)


Local:

local plr = game.Players.LocalPlayer
local mp = game:GetService("GamePassService")

game.Lighting.OD.OnClientEvent:Connect(function()
	if mp:PlayerHasPass(plr,5043985) then
		game.Lobby.VIPPART:Destroy()
	end
end)

2 comments

0

u shouldnt put it in lighting put it in replicated storage

0

^

1 answer

✓ Accepted answer

The first argument of MarketplaceService:PromptGamePassPurchase is a player Instance and the second one is the gamepass id:

MarketplaceService:PromptProductPurchase(Instance player, int64 gamePassId)

GamePassService:PlayerHasPass should be deprecated but let's treat it like it's deprecated. MarketplaceService:UserOwnsGamePassAsync is the alternative and it works MUCH better.

However it takes different arguments:

MarketplaceService:UserOwnsGamePassAsync(int64 userId, int64 gamePassId)

Now let's look at the fixed scripts:

Server:

local clickDetector = script.Parent.CL
local remote = game.Lighting.OD
local marketplaceService = game:GetService("MarketplaceService")
local gamePassId = 5043985

clickDetector.MouseClick:Connect(function(player)
	if marketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassId) then
remote:FireClient(player)
	else
		marketplaceService:PromptGamePassPurchase(player, gamePassId)
	end
end)

Client:

local player = game.Players.LocalPlayer
local remote = game.Lighting.OD
local marketplaceService = game:GetService("MarketplaceService")
local gamePassId = 5043985

remote.OnClientEvent:Connect(function()
	if marketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassId) then
		workspace.Lobby.VIPPART:Destroy()
	end
end)

1 comment

0

:v

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