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

Script says I don't own the gamepass I created myself?

Hi guys,

not going to lie, I took this script from a forum (It's literally the most basic script ever) because I refuse to code 12 lines if I can just copy paste it.

The script is ment to check if the player owns a gamepass, and then gives him a tool to his backpack and startertools. The script goes as follows:

local id = (Removed ID for privacy)
	local item = game.ServerStorage.GoldenArmor
	 
	game.Players.PlayerAdded:connect(function(player)
	    if game:GetService("GamePassService"):PlayerHasPass(player, id) then
	        local a = item:Clone()
		    a.Parent = player.Backpack
			print(player.Name .. " has the game pass!")
		else
	        print(player.Name .. " doesn't have the game pass...")
	    end
	end)

I made my own gamepass on the game's page and put it on sale, it says I own it, and yet whenever I join to check the dev console, it says I don't own the pass??

1 comment

0

why would you remove the id for privacy? lol, we can just view your roblox profile and see your gamepasses anyways.

1 answer

✓ Accepted answer

Your script is probably not working because GamePassService is deprecated, use MarketPlaceService instead. Here's a new roblox wiki article into how to make gamepasses work using this service. I'll also leave the code which lies at the end of the article here:

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
 
local gamePassID = 0000000  -- Change this to your game pass ID
 
local function onPlayerAdded(player)
 
    local hasPass = false
 
    -- Check if the player already owns the game pass
    local success, message = pcall(function()
        hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID)
    end)
 
    -- If there's an error, issue a warning and exit the function
    if not success then
        warn("Error while checking if player has pass: " .. tostring(message))
        return
    end
 
    if hasPass == true then
        print(player.Name .. " owns the game pass with ID " .. gamePassID)
        -- Assign this player the ability or bonus related to the game pass
        --
    end
end
 
-- Connect 'PlayerAdded' events to the 'onPlayerAdded()' function
Players.PlayerAdded:Connect(onPlayerAdded)

3 comments

0

Works perfect! Much appreciated :)

0

You are welcome :)

0

Where should i enter this code? in a new script?

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