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

How to ensure a player owns a gamepass?

Asked by 6 years ago

Hello,

I've been trying to get this script to work for a long time. It's supposed to check if a player has a gamepass and execute some code, however this one line keeps throwing errors.

This script is in a ScreenGUI in StarterGUI

local plr = script.Parent.Parent.Parent.Parent
local first = script.Parent.First

first.MouseButton1Click:Connect(function()
if game:GetService('GamePassService'):PlayerHasPass(plr.Name, 966815211) then
  -- Line has been removed to prevent copies
end
end)

The function "MouseButton1Click" is called and works fine, however the next line keeps throwing errors.

Yes, I've tried using MarketplaceService:PlayerOwnsAsset and in the output, it recommends using GamePassService:PlayerHasPass.

Any help would be much appreciated. :)

0
wat is da error pls tell hiimgoodpack 2009 — 6y

2 answers

Log in to vote
0
Answered by
Nowaha 459 Moderation Voter
6 years ago
Edited 6 years ago

http://wiki.roblox.com/index.php?title=API:Class/GamePassService/PlayerHasPass

Yry to remove the .Name from plr.Name

0
Don't think you can check in a local script, must be normal script. Nowaha 459 — 6y
0
Already tried this.... TheEpicCooldeal 12 — 6y
0
You need the player ID Nowaha 459 — 6y
0
so, plr.UserId Nowaha 459 — 6y
View all comments (2 more)
0
Didn't work. e.e "Unable to cast value to object." TheEpicCooldeal 12 — 6y
0
Are you sure that the script.Parent.Parent.Parent.Parent targets the player? Nowaha 459 — 6y
Ad
Log in to vote
0
Answered by
Radstar1 270 Moderation Voter
6 years ago
Edited 6 years ago

For starters, you can only use MarketPlaceService in a server script when you're checking to see if the player has a pass. Secondly, when passing the player argument their name shouldn't be included. PlayerHasPass(Player, 966815211).

So if done correctly it should output the player's name.

first.MouseButton1Click:Connect(function()
if game:GetService('GamePassService'):PlayerHasPass(plr.Name, 966815211) then
print("Player.Name")
end
end)

0
Didn't work. TheEpicCooldeal 12 — 6y
0
did you take name out of plr? Radstar1 270 — 6y

Answer this question