Item not changing parent

Hello there so I came across a problem.It is not changing the parent of the tool.All the prints came out correctly.However it does not print out 1 or 2 and yes there is an existing item in the players inventory/equipped.And of course this is not the full script.Hope you can help thanks in advanced :slight_smile:
If you have any questions about the script you can reply to this thread.

local function GivingPointAndItem(plr,playr,Item)
	local receiveplayer = game.Players:FindFirstChild(plr.Name)
	local receivecharacter = game.Workspace:FindFirstChild(plr.Name)
	local giveCharacter = game.Players:FindFirstChild(playr)
	local receiveBackPack = receiveplayer:FindFirstChild("Backpack")
	local Item = Item.Value
	print(receiveplayer)
	print(receivecharacter)
	print(giveCharacter)
	print(receiveBackPack)
	print(Item)
	if giveCharacter:FindFirstChild(Item) == true then
		print("1")
		local tool = giveCharacter:FindFirstChild(Item)
		tool.Parent = receiveBackPack
	elseif plr.Backpack:FindFirstChild(Item) == true then
        print("1")
		local tool = plr.Backpack:FindFirstChild(Item)
		tool.Parent = receiveBackPack
	end

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

Just a question, why are you doing this?

	local receiveplayer = game.Players:FindFirstChild(plr.Name)
	local receivecharacter = game.Workspace:FindFirstChild(plr.Name)
	local giveCharacter = game.Players:FindFirstChild(playr)

You’re just using FindFirstChild() unnecessarily

To find the player/character of the person which wants to give an item to the other person receiving it.Therefore when the remote is activated it will transfer the tool from the giving person to the receiving person inventory.In case i didnt make it clear this script is made with an intent of transferring tools to the other person inventory

I see that but why are you using :FindFirstChild() ? You should just do

local receiveplayer = game.Players[plr.Name]
local receivecharacter = receiveplayer.Character
local giveCharacter = game.Players[playr]
1 Like

Oh.I got a question doesnt both of them have the same outcome?What is the difference.Sorry im new to scripting

1 Like

Yeah they do have the same outcome but you shouldn’t call a function if you’re not going to use what it returns, it’s just clutter. Plus using FindFirstChild in this instance would be slower than doing it the other method.

	elseif plr.Backpack:FindFirstChild(Item) == true then

What’s the point of the variable receiveplayer if the plr variable is the player object?

I think you should rewrite the whole function, was giveCharacter supposed to reference the players character? If not, why are you looking for the tool in the player object here; if giveCharacter:FindFirstChild(Item) == true then?

Are your tools parented under the character or their backpack?

if giveCharacter:FindFirstChild(Item) == true then
elseif plr.Backpack:FindFirstChild(Item) == true then

`It really depends as when the tool is unequipped it will change its parent to backpack under the player.However when the item is equipped the parent changes to the character.Therefore this scripts checks whether the tool is parented to the player or the charcter and does the function depending on the situation.

It really depends if the giving player decides to unequip the tool during this period.Let me explain the full script.Basically when the giving player activates a remote it will give a gui to the receiving player which then has unlimited time to accept or reject the tool.During that time period the giving player still has an option to unequiped/equip the tool he wants to give.

if giveCharacter:FindFirstChild(Item) == true then
elseif plr.Backpack:FindFirstChild(Item) == true then

This two codes help in locating where the tool currently is after the receiving player confirms that he wants to accept the tool

Hi, if you are using an objectvalue then I could actually never found a way to work with that.

My suggestion:
Use a Stringvalue and name the value of the stringvalue to the name of the Item that you want and try
local Toolname = StringValue.Value
then you can try your
“if giveCharacter:FindFirstChild(Toolname) == true then”
or you can set a boolvalue to check if the player has that item or not
example:
“if giveCharacter:FindFirstChild(CheckForItem).Value == true then”
and to make the bool value true you would obviously need something to make it true like touching a part or what ever you want it to
If u want more explanations then dont be afraid to ask

Hello,thanks for replying.However I am not using an objectvalue but using a stringvalue.