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?
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.
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)