Problem With Looping Through Player's Backpack

I am trying to make a passport/security system. This script is when the person equips the passport and put the passport on the touch part, the tool name is the player’s name. I am trying to get everything in the player’s backpack so I tested using the loop script, the problem is it didn’t print “a”.

script.Parent.Touched:Connect(function(hit)
	if hit.Parent.ClassName == "Tool" then
		if game.Players:FindFirstChild(hit.Parent.Name) then
			local player = game.Players:WaitForChild(hit.Parent.Name)
			script.Parent.Parent.Parent.Screen.SurfaceGui.Texts.Name2.Text = "Name: "..player.Name
			script.Parent.Parent.Parent.Screen.SurfaceGui.Texts.AccountAge.Text = "Account Age: "..player.AccountAge.. " days"
			for i,v in pairs(game.Players:WaitForChild(hit.Parent.Name).Backpack:GetChildren()) do
				print("a")
			end
		end
	end
end)

You should use Players:GetPlayerFromCharacter() to get the player.

Also, if the player has no tools, it will not print a.

Are there any other tools in their backpack? If the tool is equipt it is parented to the character, not the backpack.

2 Likes

I’m sure there’s tools, because of the passport, and it detects by the passport touching the touch part.

Ohh, I didn’t know that, thank you for telling me.