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

I am trying to make a gamepass giver script, but my code won't work but doesn't have any errors?

This is my current code which is in a script in ServerScriptService

local tool = game.Lighting.Glock17
local gamepass = 4893873   

local function onPlayerAdded(plr)
	local hasPass = false
	if game:GetService("GamePassService"):PlayerHasPass(plr, gamepass) then
		tool:Clone().Parent = game.Players.LocalPlayer.Backpack
	else
		print("player doesn't own pass")
	end
end

This is an updated script but still doesn't work

local tool = game.Lighting.Glock17
local gamepass = 4893873   

local function onPlayerAdded(plr)
	local hasPass = false
	if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(plr, gamepass) then
		tool:Clone().Parent = game.Players.LocalPlayer.Backpack
	else
		print("player doesn't own pass")
	end
end

3 answers

Try...

local allow = (
        game:GetService('MarketplaceService'):UserOwnsGamePassAsync(player.userId, 1234567) -- Paste your game pass id here
    )
 
    if allow then
			 -- continue with script

1 comment

0

what

###This is because the first argument is the UserId of the player, not the Player object itself. Also, why are you using LocalPlayer when it is nil on the server and you already had the player defined? It is also worth mentioning that Lighting should not be used as storage, use ReplicatedStorage or ServerStorage.

local tool = game.ReplicatedStorage.Glock17
local gamepass = 4893873   
local MarketplaceService = game:GetService("MarketplaceService")

local function onPlayerAdded(plr)
    local hasPass
    hasPass = MarketplaceService:UserOwnsGamePassAsync(plr.UserId, gamepass)

    if hasPass then
        tool:Clone().Parent = plr.Backpack
    else
        print("player doesn't own pass")
    end
end

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