local ServerStorage = game:GetService("ServerStorage")
local key = ServerStorage["keycardL2"]
local marketplacescervice = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

local gamepassID = 429957

local function onPlayerAdded(player)
	local haspass = marketplacescervice:UserOwnsGamePassAsync(player.UserId, gamepassID)
	
	if haspass then
		print(player, "owns the gamepass with ID", gamepassID)
		local key1 = key:Clone()
		key1.Parent = player:WaitForChild("Backpack")
		key1:Clone().parent = player.StarterGear
		end
	end
	Players.PlayerAdded:Connect (onPlayerAdded())

the error is ServerScriptService.Script:11: attempt to index nil with 'UserId'

3 comments

0

You didn't pass the parameter of "player" in line 18.

0

thanks!

0

so i deleted the brackets or () whatever you call them where you live and so far i think it works