Tag system working but then breaking?

Hello! my name is bullet, and today i’ve ran into yet another problem.
I was working on a tag system for items in a factorylike game, and it works for every system except the selling part.

So it refines, then manufactures this item, carrying the tag over each one, and then at the end, the tag is there [ it’s a texture ], it has the player’s name, and yet when it hits the sell pad, it gives it an error.

the code that is erroring:
print(Item:FindFirstChildOfClass("Texture").Name)
although, this code works on every other thing, including the tag carryover system.
i just don’t understand why it’s erroring, as it doesn’t error on any other thing if i put it in there.

the rest of the code:

local debounce = true


function Main(Item)
	if debounce then
		print(Item.Name)
		debounce = false
		script.Parent.CanCollide = true
		script.Parent.Color = Color3.fromRGB(255, 255, 0)
		local player = game.Players:FindFirstChild(Item:FindFirstChildOfClass("Texture").Name)
		Item:Destroy()
		player:WaitForChild("leaderstats"):WaitForChild("TESTINGCURRENCY").Value += 10
		wait(0.5)
		script.Parent.Color = Color3.fromRGB(0, 255, 0)
		script.Parent.CanCollide = false
		debounce = true
	end
end



	
script.Parent.Touched:Connect(function(Item)
	if Item.Name == "Shovel" then
		Main(Item)
		print(Item:FindFirstChildOfClass("Texture").Name)
	end
end)		

thanks for reading, and please help if you can!
if you want the other one’s codes, then just ask.

What specific error does it give? And does it give an error when you call Main(Item)?

1 Like

Attempt to index nil with Name, and no error when trying to call the Item, it prints the items name and it works fine.

doesn’t find “Texture” in your “Item”, you didn’t put it there, but to avoid the error and check it, just do this

if Item:FindFirstChildOfClass(“Texture”) then
–Script
else
print(“No texture was found”)
end

here’s the thing, the texture is there, it’s in the item, i’ve checked it multiple times.

print(Item:FindFirstChildOfClass("Texture").Name)

Error is here?

[quote=“bullettrain5, post:1, topic:1651221”]
print(Item.Name)`
[/quote]

I think the error might be here.

Later on in the code, Item is destroyed (for some reason)

[quote=“bullettrain5, post:1, topic:1651221”]
Item:Destroy()
[/quote]

Maybe that isn’t actually the error.

Nevermind you mentioned that wasn’t the error

@bullettrain5 can you please take a screenshot of the output (with the error)?

yes, i will do that, hold on


this is the exact error

yep
it is right there, even though the texture is under the item

just another screenshot right here to prove it’s right there:
image

What you are doing is defining the ‘Item’ as some sort hit. Instead of saying:

script.Parent.Touched:Connect(function(Item)
	if Item.Name == "Shovel" then
		Main(Item)
		print(Item:FindFirstChildOfClass("Texture").Name)
	end
end)		

You would do this instead:

script.Parent.Touched:Connect(function(Item)
	if Item.Parent.Name == "Shovel" then
		Main(Item.Parent)
		print(Item.Parent:FindFirstChildOfClass("Texture").Name)
	end
end)		
1 Like
local players = game:GetService("Players")
local part = script.Parent
local debounce = false

local function mainMethod(item)
	if debounce then
		return
	end
	debounce = true
	part.CanCollide = true
	part.Color = Color3.new(1, 1, 0)
	item:Destroy()
	task.wait(0.5)
	part.Color = Color3.new(0, 1, 0)
	part.CanCollide = false
	debounce = false
end

part.Touched:Connect(function(hit)
	if hit.Parent.Name == "Shovel" then
		mainMethod(hit.Parent)
	end
end)