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

Gamepass script not granting tools, even though I own it?

Asked by 6 years ago

Hey guys. So, I'm not at all new to gamepasses, but for whatever reason it may be, the game claims I do not own the gamepass I created myself (and the page says I own it aswell!)

I made a print to show me if I have it or not, and when playing the game, it prints the "doesnt own", even though, very clearly, I do own it.

Is this a scripting error?

id = mypassidwenthere
game.Players.PlayerAdded:connect(function(plr)
    repeat wait() until plr.Character
    if game:GetService("GamePassService"):PlayerHasPass(plr, id) then
        local tool = script:FindFirstChild("Spear")
            tool:Clone().Parent = plr.Backpack
            tool:Clone().Parent = plr.StarterGear
        print("Given")
    else
        print("doesnt own")
    end
end)
0
"mypaddidwentthere" is not a valid pass ID. Also https://twitter.com/RbxDevTips/status/430195544628006912 LostPast 253 — 6y
0
That wasn't the actual ID haha! My bad, I didn't explain that properly. That was for privacy purposes. I'll check the link out, thanks User#20989 0 — 6y
0
Odd, even when publishing and testing it in the player client it still claims I do not own the pass. User#20989 0 — 6y
0
Doesn't work if PlayerHasPass is called in LocalScript or in Studio User#17685 0 — 6y

1 answer

Log in to vote
2
Answered by 6 years ago

PlayerHasPass is deprecated; use UserOwnsGamepassAsync instead. My buddy vissequ made a script for this purpose and he's welcome to share it with anyone.

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

local gamePassID = --YourGamePassIdHere 

function onPlayerSpawned(player) 

    local hasPass = false

    -- Check if the player already owns the game pass
    local success, message = pcall(function()
        hasPass = MarketplaceService:UserOwnsGamePassAsync(player.userId, gamePassID)
        print("Has Game Pass")
    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
    -- Your Code Here
    end
end 

game.Players.PlayerAdded:connect(function(player)
  player.CharacterAdded:connect(function()
    onPlayerSpawned(player)
  end)
end)

-- Connect 'PlayerAdded' events to the 'onPlayerAdded()' function
Players.PlayerAdded:Connect(onPlayerSpawned)
--Script Created by Vissequ

(This Script is confirmed working, so If it still doesn't work, it's on you.) P.S. I highly recommend you don't put your tools inside your script, because that's what you're refrencing in your script, and you put them in ReplicatedStorage. Also, This script won't run if it isn't in Workspace or ServerScriptService, as a Server Script.

0
Turns out UserOwnsGamepassAsync does the trick! Thanks, and I'll be sure to move my tools out of my script. User#20989 0 — 6y
Ad

Answer this question