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:
01 | local this = script.Parent |
02 | local CL = script.Parent.CL |
03 | local mp = game:GetService( "GamePassService" ) |
04 | local remote = game.Lighting.OD |
05 | local mp 2 = game:GetService( "MarketplaceService" ) |
06 |
07 | CL.MouseClick:Connect( function (plr) |
08 | if mp:PlayerHasPass(plr, 5043985 ) then |
09 | remote:FireClient(plr) |
10 | else |
11 | mp 2 :PromptGamePassPurchase( 5043985 ,plr) |
12 | end |
13 | end ) |
Local:
1 | local plr = game.Players.LocalPlayer |
2 | local mp = game:GetService( "GamePassService" ) |
3 |
4 | game.Lighting.OD.OnClientEvent:Connect( function () |
5 | if mp:PlayerHasPass(plr, 5043985 ) then |
6 | game.Lobby.VIPPART:Destroy() |
7 | end |
8 | end ) |
The first argument of MarketplaceService:PromptGamePassPurchase
is a player Instance and the second one is the gamepass id:
1 | MarketplaceService:PromptProductPurchase(Instance player, int 64 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:
1 | MarketplaceService:UserOwnsGamePassAsync(int 64 userId, int 64 gamePassId) |
Now let's look at the fixed scripts:
Server:
01 | local clickDetector = script.Parent.CL |
02 | local remote = game.Lighting.OD |
03 | local marketplaceService = game:GetService( "MarketplaceService" ) |
04 | local gamePassId = 5043985 |
05 |
06 | clickDetector.MouseClick:Connect( function (player) |
07 | if marketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassId) then |
08 | remote:FireClient(player) |
09 | else |
10 | marketplaceService:PromptGamePassPurchase(player, gamePassId) |
11 | end |
12 | end ) |
Client:
01 | local player = game.Players.LocalPlayer |
02 | local remote = game.Lighting.OD |
03 | local marketplaceService = game:GetService( "MarketplaceService" ) |
04 | local gamePassId = 5043985 |
05 |
06 | remote.OnClientEvent:Connect( function () |
07 | if marketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassId) then |
08 | workspace.Lobby.VIPPART:Destroy() |
09 | end |
10 | end ) |