Sword Fighting: attempt to index nil with 'Backpack'

I’m on my phone as of now, so I quickly threw this together:

local marketplaceService = game:GetService('MarketplaceService')
local gamepassID = 40443369

local dbPlayers = {}
local db = 0

function Claim(val, parent)
	table.insert(dbPlayers, parent)
	
	if val then
		game.ServerStorage.HighSword:Clone().Parent = parent.Backpack
	else
		game.ServerStorage.ClassicSword:Clone().Parent = parent.Backpack
	end
end

script.Parent.Touched:Connect(function(Hit)
	if os.clock() - db >= .1 then
		db = os.clock();
		
		print("Sword Detector: Touched")

		local Player = game:GetService("Players"):GetPlayerFromCharacter(Hit.Parent)

		if Player then
			local claimed = false;

			for i, v in pairs(dbPlayers) do
				if v == Player then
					claimed = true;

                                      break;
				end
			end

			if not claimed then
				if marketplaceService:UserOwnsGamePassAsync(Player.UserId, gamepassID) then
					print("Sword Detector: User owns pass")

					spawn(function() Claim(true, Player) end)
				else
					spawn(function() Claim(false, Player) end)
				end
			end
		end
	end
end)
1 Like