What? Can someone tell me why this doesn't works

Okay so,
I have this function:

local function Run()
	if Mouse.Target then
		if Mouse.Target:IsDescendantOf(workspace.Accorns) and not Interaction then
			Interaction = Mouse.Target
		end
	end
	if Interaction ~= nil then
		if Interaction.Name == 'Accorn' then
			Notification("Collected +1 Accorn!")
			Events.Pickup:FireServer(Interaction)
			print(Interaction.Name)
			return
		end
		if Interaction.Name == 'Tree' then
			if Events.HasBellotas:InvokeServer(Interaction) then
				Events.Tree:FireServer(Interaction)
			else
				
				end
		end
	end
end

Interaction is defined, but for some reasons, it errors:
attempt to index nil with ‘Name’

I mean, what the hell, I am checking here:
image
If interaction is not nil
But when I print interaction name, it says nil…uhmm

So in your function, you have the line,

if Interaction.Name == 'Accorn' then

The word: “Acorn” is spelled wrong.

That doesn’t matters, it’s the name I have for acorns

can you convert all the interaction.Name statements into one if statement

you are making another if statement of interaction.Name instead make it elseif

That wouldn’t change anything, what I need to check is the name, to do different actions.
image

then what is interaction then?

Maybe because Mouse.Target is not actually descendant of workspace.Accorns, try something like that, I guess:

local function Run()
	if Mouse.Target ~= nil then
		if Mouse.Target.Name and not Interaction then
			Interaction = Mouse.Target
		end
	end
	if Interaction ~= nil then
		if Interaction.Name == 'Accorn' then
			Notification("Collected +1 Accorn!")
			Events.Pickup:FireServer(Interaction)
			print(Interaction.Name)
			return
		end
		if Interaction.Name == 'Tree' then
			if Events.HasBellotas:InvokeServer(Interaction) then
				Events.Tree:FireServer(Interaction)
			else
				print(false)
			end
		end
	end
end

It’s descendant of workspace.Acorns!

The thing is:
This runs:
image
but then, it errors when I try to print for example (Interaction.Name)
Saying it’s nil

have you tried Mouse.Target.Parent?

I don’t need it, I need mouse.Target not the parent of it :confused:

you are setting it to an object tho and you cant print an object so it returns nil

try this

Interaction = Mouse.Target.Name

Not to be rude, you are not helping at all.
I am not printing an object, and you can print an object since it returns its name.
I am printing Name of it

this might not help but

have you tried printing Mouse.Target.Name?

What is “Acorn”?

I ran this code to test:

local Players = game:GetService(“Players”)
local player = Players.LocalPlayer
local Mouse = player:GetMouse()

local Interaction
local function Run()
if Mouse.Target ~= nil then
if Mouse.Target.Name and not Interaction then
Interaction = Mouse.Target
end
end

if Interaction ~= nil then
	print(Interaction)
	if Interaction.Name == 'Baseplate' then
		print(Interaction.Name)
		return
	end
	if Interaction.Name == 'Tree' then
		
	end
end

end

while true do
Run()
wait()
end

And this generates no errors for me.

image
so, basically, when you click on a tree, it places ‘Acorn’ mesh in Acorns folder.

Hmm. I think I know what is going on.
So I assume that Run() is being looped and that Interaction is a global value.

Could it be that Interaction becomes a different value other than a basepart?

Try placing:
print(Interaction, Interaction:GetFullName())

Before:
if Interaction.Name == ‘Accorn’ then

See if we can find if there is a problem there.

No problem, it printed well the name.
https://gyazo.com/4d91c8baf362b683c3b8d6e4d289492d
But than it errors
image

What does the output say?

Also, do you mean with that picture that Interaction is nil at the if check or at the print?
If "If Interaction.Name == ‘Acorn’ then " passes you should move the print(Interaction) lower to just before it the error line.

So does that mean that the error on line 166 is
“If Interaction.Name == ‘Acorn’ then” or “print(Interaction.Name)”