Player variable resetting

function ToolHandlerModule.PlayerParentHandler(Item, Player)


	if Item.Parent.Parent == Player then
				

			local ItemCosmetic = Item:FindFirstChild("CosmeticValue").Value
			SlingHandler.SlingItem(Player, ItemCosmetic, false)
		
				print("Equipped, TEST")
				
			end
		end
			
		
		
	if Item.Parent.Parent == game.Workspace then
			

				print(Player,"Deleted, TEST")

				local ItemCosmeticUn = Item:FindFirstChild("CosmeticValue").Value
			SlingHandler.UnslingItem(Player, ItemCosmeticUn)
		end
	end
end

module isnt activated if player is nil and works fine for the first function but on second function player nils

 nil Deleted, TEST  -  Server - ToolHandler:50

I don’t think you pasted the whole code in there. There is no second function header which if that is truly the case would result in Player being nil because it is just running the code straight away and it probably isn’t defined above. If not maybe pasting the whole code in correctly might give a better idea.

1 Like

sorry not second function i meant 2nd if statement

What he means is the second ‘end’ after the first if statement and just before the second if statement is closing the function.

Indenting your code properly will make it easier to notice those kinds of things.

function ToolHandlerModule.PlayerParentHandler(Item, Player)
	if Item.Parent.Parent == Player then
		local ItemCosmetic = Item:FindFirstChild("CosmeticValue").Value
		SlingHandler.SlingItem(Player, ItemCosmetic, false)
		print("Equipped, TEST")
	elseif Item.Parent.Parent == game.Workspace then
		print(Player,"Deleted, TEST")
		local ItemCosmeticUn = Item:FindFirstChild("CosmeticValue").Value
		SlingHandler.UnslingItem(Player, ItemCosmeticUn)
	end
end

1 Like

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