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

How to check if someone has a gamepass?

Hey everyone, I'm new here. I was wondering how I'd be able to make a TextButton that when clicked, would check if the user has a gamepass and if they do, execute the code

game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 64

and if not, prompt them to purchase the gamepass. How would this be possible? Thanks! Also, is it safe to put the purchase checking code in localscript or not?

2 answers

To check you can do a simple function when they join the game such as:

-- Textbutton Clicked

local Player = game.Players.LocalPlayer
function checkPass(Plr)
	return game:GetService("MarketplaceService"):PlayerOwnsAsset(Plr, gamePassID)
end

TextButton.MouseButton1Click:connect(function()
	if checkPass(Plr, gamePassID Here) then
		-- Code you want to run here
	end
end)



-- Join game version
function checkPass(Plr, gamePassID)
	return game:GetService("MarketplaceService"):PlayerOwnsAsset(Plr, gamePassID)
end

game.Players.PlayerAdded:connect(function(Player)
	if checkPass(Player, GamepassID) then
		-- Code to run	
	end
end)

6 comments

0

I'm not sure if I get this. It's meant to happen when a TextButton is clicked.

0

Check my script again I updated it

0

Thank you, but how do I prompt them to buy it?

0

On line 9 where you see "checkpass" add "else" then the prompt purchase function

0

thank you!

0

Accept his answer :P

Here you go Amijo!

--LocalScript

--Put this in your TextButton.

local GamePassID = 0 --Put Your gamepass ID here :D
local LocalPlayer = game:GetService('Players').LocalPlayer
local MarketplaceService = game:GetService('MarketplaceService')

script.Parent.MouseButton1Click:Connect(function()
if MarketplaceService:UserOwnsGamePassAsync(LocalPlayer.UserId, GamePassID) then
LocalPlayer.Character.Humanoid.WalkSpeed = 64
else
print('Error: User does not Have GamePass')
end
end)

1 comment

0

Make sure to accept my Answer if this Helped! :D

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