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

Open Frame If Player Owns Pass?

Asked by
Rynappel 212 Moderation Voter
5 years ago

I have a textbutton and you click it and its supposed to open a frame ONLY if you have a gamepass, but it doesnt work? Why not though..

01local frame = script.Parent.Parent.Parent.TeleportFrame
02local player = game.Players.LocalPlayer
03local id = 7617401
04 
05script.Parent.MouseButton1Click:Connect(function()
06    if game:GetService("MarketplaceService"):PlayerOwnsAsset(player, id) then
07        frame.Visible = not frame.Visible
08    else
09        game:GetService("MarketplaceService"):PromptGamePassPurchase(player, id)
10    end
11end)
2
Use PlayerOwnsGamePassAsync. namespace25 594 — 5y

2 answers

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

You should be using this function https://developer.roblox.com/en-us/api-reference/function/GamePassService/PlayerHasPass

The DevHub for PlayerOwnsAsset strictly says not to use it with GamePasses.

Ad
Log in to vote
1
Answered by
raid6n 2196 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

use UserOwnsGamePassAsync

01script.Parent.MouseButton1Click:Connect(function()
02local id = YOUR_ID_HERE
03 
04game:GetService("MarketplaceService").PromptGamePassPurchaseFinished:Connect(function(plr,ido,purchased)
05    if purchased and ido == id then
06        script.Parent.Parent.Parent.TeleportFrame.Visible = true
07    end
08end)
09 
10game.Players.PlayerAdded:Connect(function(plr)
11    plr.CharacterAdded:connect(function(char)
12        if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(game.Players[char.Name].UserId, id) then
13            script.Parent.Parent.Parent.TeleportFrame.Visible = true
14        end
15    end)
16end)

Answer this question