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

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

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?

2 comments

0

you should use indentation

0

line 4-5 are connected

2 answers

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.

2 comments

0

You can format a hyperlink by Text

0

Didn't know that, thank you for that.

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)

2 comments

0

Fix your script please, doesn't work

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.

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