Attempt to index nil with parent

When entering a part, the script will supposedly detect what the hasCloned bool’s value is. If it is false then it would have to clone the tool and if true it just sets its parent back to the player backpack (somewhere in my script I just set its parent elsewhere just in case the player will use it again). When tested, the script wouldn’t work, the tool doesn’t get cloned at all and also doesn’t go the player’s backpack nor character and it prompts attempt to index nil with ‘parent’ in the output. Help pls


--using ZonePlus module--
	if Debounce == false then
		Debounce = true
		local char = Player.Character or Player.CharacterAdded:Wait()
		local toolClone
		if not char:FindFirstChild(Tool.Name) then
			if not hasCloned then
				toolClone = Tool:Clone()
				toolClone.Parent = Player.Backpack
				toolClone.Name = Tool.Name
				local toolOwnerTag ="IntValue", toolClone)
				toolOwnerTag.Name = "ToolOwnerTag"
				toolOwnerTag.Value = Player.UserId
				hasCloned = true
				if not table.find(ffaAreaTouchers, Player.UserId) then
					table.insert(ffaAreaTouchers, Player.UserId)
			elseif hasCloned then
				if toolClone.Parent ~= Player.Backpack then
					toolClone.Parent = Player.Backpack
					local toolOwnerTag = toolClone:FindFirstChild("ToolOwnerTag")
					toolOwnerTag.Value = Player.UserId
					if not table.find(ffaAreaTouchers, Player.UserId) then
						table.insert(ffaAreaTouchers, Player.UserId)
		Debounce = false

where did you declare Tool before you called :Clone() on it?

below local char = Player.Character or Player.CharacterAdded:Wait()

“Attempt to index nil with parent” appears when you’re attempting to call .parent on something that does not exist or yet exist.

I suspect that the tool you’re attempting to clone either is somewhere else in the game or outright does not exist.

Make sure that the tool exists and that the variable Tool is defined correctly as that tool.

Though it would help if you could give a screenshot of the error message. It’d help in pinpointing where the code breaks down and how to narrow down possible suspects.

line 58 it said

Well, its obvious, try moving the local toolClone outside the scope of the playerEntered event.

local toolClone; --// Move it outside the event


Because whenever the event fires, toolClone is being reset.

1 Like

this is where you declared the player’s character, I was asking for where you declared the Tool variable