What's the problem with this script?

I made this script so when you touch the door it will move the passport in your inventory to replicated storage

script.Parent.Touched:Connect(function(player)
	local backpack = game.Players:FindFirstChild(player.Parent.Name).Backpack
	if backpack:FindFirstChild("Passport") then
		print("yooo")
		backpack.Passport = game.ReplicatedStorage
	end
end)

and this in another doort to take it back

script.Parent.Touched:Connect(function(player)
	local Passport = game.ReplicatedStorage:FindFirstChild("Passport")
	local backpack = game.Players:FindFirstChild(player.Parent.Name).Backpack
	if Passport then
		print("yooo")
		Passport = backpack
	end
end)

what’s the problem?

edit: this is the error

Passport is not a valid member of Backpack "Players.ANRTNT.Backpack"

I think it’s that you are looking for Player’s parent. Try using player.Backpack in the FindFirstChild() function.

Edit: also do

Passport.Parent = backpack

I typed player but it actually is the playe’s bodypart so it’s parents are needed

1 Like

You are not setting the Passports parrent. Do

Passport.Parent = backpack

oh it worked! can I ask why I should have used parent for that?

1 Like

When you do the = at the end of your Passport.Parent, it will set It’s parent to the one after =., which in this case is ReplicatedStorage. It changes it’s parent.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.