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

Game pass detection not functioning correctly?

Asked by
Plieax 66
5 years ago

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)
0
u shouldnt put it in lighting put it in replicated storage MineBlow111 39 — 5y
0
^ Griffi0n 315 — 5y

1 answer

Log in to vote
1
Answered by
Griffi0n 315 Moderation Voter
5 years ago
Edited 5 years ago

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)
0
:v User#19524 175 — 5y
Ad

Answer this question