I am trying to make a gamepass script to give players a tool when they join the game
local MarketplaceService = game:GetService("MarketplaceService") local Players = game:GetService("Players") local Gamepasses = { ["5688925"] = game.ServerStorage["Entry Permit"], ["3688870"] = game.ServerStorage["Tommy Gun"], ["4653506"] = game.ServerStorage["M1 Garand"], ["3423531"] = game.ServerStorage["Knife"], } function CheckPasses(Player) for _PassID,_PassTool in pairs (Gamepasses) do if MarketplaceService:UserOwnsGamePassAsync( Player.UserId, _PassID ) then _PassTool:Clone().Parent = Player.Backpack end end end local function onPlayerAdded(Player) local hasPass = false -- Check if the player already owns the game pass local success, message = pcall(function() hasPass = MarketplaceService:UserOwnsGamePassAsync(Player.UserId, Gamepasses) 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 print(Player.Name .. " owns the game pass with ID " .. Gamepasses) end end -- Connect 'PlayerAdded' events to the 'onPlayerAdded()' function Players.PlayerAdded:Connect(onPlayerAdded)