[resolved] Gamepass Service

GamepassService to MarketplaceService

You can format codeblocks using backticks or squigglies:

Input:
```
--code here
```

This too:
~~~
--code here
~~~

Output:

--code here

GamePassService to my knowledge is deprecated and only works on old gamepasses that use asset id’s. It has otherwise been superceded by MarketplaceService, which works for gamepasses that use their own gamepass id.

local mps = game:GetService("MarketplaceService")

Also, this argument takes a user id as its first argument, not the player itself:

-- where this line would be:
if mps:UserOwnsGamePassAsync(player, 3795613) then

--replace it with this line:
if mps:UserOwnsGamePassAsync(player.UserId, 3795613) then

You might also want to reference the player from the root instead of relatively, just in case you want to move the script somewhere else and avoid the hassle of changing it again:

local player = game:GetService("Players").LocalPlayer

You can also use the player’s Team instead of its TeamColor here, it’s just cleaner, and is sure to be less buggy:

player.Team = game.Teams.Driver

Altogether:

local player = game:GetService("Player").LocalPlayer
local mps = game:GetService("MarketplaceService")

function Click(mouse)
	if mps:UserOwnsGamePassAsync(player.UserId, 3795613) then
		player.Team = game.Teams.Driver
	end
end

That’s a little confusing, how old is the gamepass you are testing for?

Also, I forgot that this was a Script, oops…

Apparently, this devforum post, which dates when this gamepass thing was changed, is here:

GamePassService is the correct service to use here, make sure to change it. The method for it, based on the dev wiki, is GamePassService:PlayerHasPass.

Where is the Click function used in your script? Is it bound to a ClickDetector?

PlayerGui, Script not a LocalScript as it is a team script

Is this script replicated to every player on start, like it was placed in StarterGui?

Yes it is in StarterGui so uh I am not sure what the problem is

Scripts aren’t able to get the LocalPlayer because they are server-sided, you should probably use script:FindFirstAncestorOfClass("Player") instead.

So I replace this with script:FindFirstAncestorOfClass(“Player”)

1 Like

Yes.

Or just convert over to a LocalScript. Using script instances in StarterGui (PlayerGuis by nature of where the contents of StarterGui get copied into) is bad practice and not recommended. Considering it’s a client-side only container, you should not be using server-side code here.

Change completely over to a LocalScript and use LocalPlayer. Be sure to also use the id of the game pass rather than the old one and feed it as the second argument of UserOwnsGamePassAsync (@goldenstein64 it’s two words by the way, Gamepass would throw an error).

If it’s a team script (as in you need a game pass to change to a team), set up the client-side of the code to click a button and then fire a remote. On the server, it checks if the player has access to the team (if it’s free, needs to be purchased, has a whitelist, so on). If they do, change their team.

2 Likes

There’s also a tutorial by @Enqrypted on his Youtube channel on how to make gamepasses. It works, too.

1 Like