Tool is 'showing' as nil

I’m making a backpack, but when I try to put the tool back in the backpack from the plr, it tells me I am indexing nil with Parent. I printed the tool name below and it’s the same name but it’s still showing as nil. My current code:

local equipped = false
local plr = game.Players.LocalPlayer
local backpack = plr:WaitForChild("Backpack")
script.Parent.MouseButton1Click:Connect(function()
	local tool = backpack:FindFirstChild(script.Parent.Text)
	if equipped == false then
		tool.Parent = plr.Character
		print(tool.Name)
		print(tool.Parent.Name)
		equipped = true
	elseif equipped == true then
		tool.Parent = backpack
		equipped = false
	end
end)

Thanks for your assistance! :slight_smile:

First of all, you should try to do it from the Server. I am not quite sure if the client is able to give out tools just like that

It still gives out the same error. :frowning:

You can’t use local plr = game.Players.LocalPlayer on the Server. Read Roblox-Client-Server-Model and Remote-Functions-and-Events to understand the communication between the Server and Client in detail

Were you referring to the tool.Parent = plr.Character or the tool.Parent = backpack in your earlier post? If you were talking about the former, then it works. Also, I did use remote event to connect to the server, I know how to use it.

Simple because the tool isnt in backpack anymore

u see this says it is in the backpack but it isnt so it gives nil

Variables don’t work like that. Once they’re defined, they’re like that. They stick with their values, and they don’t keep checking in that place to define it again like that.

Well too bad you made it change everytime you click

oh yeahhh thanks for telling me that I’ll mark your post as solution