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

Why is my gamepass script not working? And why am i getting an error?

This is in a localscript, this is also my first time actually making a gamepass, i never actually cared for it in the past, so if anyone can help me it'd be great, i am having problems with it:

local pewdiepass = 599082309
local gpserv = game:GetService("GamePassService")

if gpserv:PlayerHasPass(plr, pewdiepass) then
		subs.Value = subs.Value +785
		money.Value = money.Value +1250
	end

this is the error code:

Game passes can only be queried by a Script running on a ROBLOX game server

1 answer

✓ Accepted answer

You're going to want to run this on the server, as opposed to the client, so put this in a server script. Also, you never defined "plr", "subs", or "money" and it'd be much easier if you used a .PlayerAdded function

local passId = 599082309
local gps = game:GetService('GamePassService')

game.Players.PlayerAdded:connect(function(player)
	local subs --Define this here
	local money --Define this here

	if gps:PlayerHasPass(player, passId) then
		subs.Value = subs.Value + 785
		money.Value = money.Value + 1250
	end
end)

6 comments

0

i tried that same thing and it gave me the same error

0

Go to "Configure your game" not "Configure this place" and enable "Enable Studio Access to API Services"

0

I already did that, does my HttpService need to be on?

0

Use :PlayerOwnsAsset()

0

Nevermind, I figured it out, It is highly recommended by roblox to use PlayerOwnsAsset, i didn't read that part, but thanks for the help atleast, i will accept the answerfor your effort

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