Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago
Edited 6 years ago

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

Log in to vote
0
Answered by
chomboghai 2044 Moderation Voter Community Moderator
6 years ago

Use UserOwnsGamePassAsync from the MarketplaceService instead. After the gamepass update, you need to use this method instead.

Ad
Log in to vote
0
Answered by
ABK2017 406 Moderation Voter
6 years ago

Try...

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

    if allow then
             -- continue with script
0
what User#19524 175 — 6y
Log in to vote
0
Answered by 6 years ago

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

Answer this question