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

How to add a check to see if own gamepass and if so continue to work?

Asked by 4 years ago
Edited 4 years ago
game.Players.PlayerAdded:connect(function(p) 
p.CharacterAdded:connect(function(c) 
repeat wait() until p:FindFirstChild("Backpack") 
game.ServerStorage.Weps:GetChildren()[math.random(1, 
#game.ServerStorage.Weps:GetChildren())]:clone().Parent = p.Backpack
end) 
wait(2)
end)

how to convert this to working only if owning gamepass?

0
you should use indentation proqrammed 285 — 4y
0
line 4-5 are connected itadakimasu_Kurepu 29 — 4y

2 answers

Log in to vote
1
Answered by 4 years ago

Well first of all..., that's not really how to use gamepasses, that is just checking if the player has a tool. You use MarketplaceService, recommend you look at this: https://developer.roblox.com/en-us/api-reference/class/MarketplaceService/index.html If you wanted to check if the person has the gamepass you can use

local hasPass = false 

    local success, errormessage = pcall(function()
        hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID) -- this checks if the player has the gamepass or not.
    end)

After this, you can just add onto the script as if the user has a certain gamepass, you can make it do something, and if the user does not.

0
You can format a hyperlink by [Text](link) Ziffixture 6913 — 4y
0
Didn't know that, thank you for that. Auxatier 59 — 4y
Ad
Log in to vote
1
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

You can use MarketplaceService‘s :UserOwnsGamePassAsync() method to validate whether a certain Player owns a specified Gamepass via it’s affiliated ID.

local MarketplaceService = game:GetService("MarketplaceService")
local GamepassId = --// GamepassId

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

Players.PlayerAdded:Connect(function(Player)
    local Backpack = Player:WaitForChild("Backpack") 
    Player.CharacterAdded:Connect(function(Character)
        if (MarketplaceService:UserOwnsGamePassAsync(Player.UserId, GamepassId) then
            local Weps = ServerStorage:WaitForChild("Weps"):GetChildren()
            Weps[math.random(1, #Weps)]:Clone().Parent = Backpack
        end
    end) 
end)
0
Fix your script please, doesn't work itadakimasu_Kurepu 29 — 4y
0
That is not my job. The Output will tell you what your problem is, and you can work from there yourself. This isn’t a request site. I made a syntax error, that way my fault I apologize. I had resolved it before I had the chance to let you know. Please try the code above again. Ziffixture 6913 — 4y

Answer this question