Help with mouse target and table

  1. What do you want to achieve? I want to make so when to mouse.Target == table then print

  2. What is the issue? It is not working or printing errors in output that I can’t fix

  3. What solutions have you tried so far? I tried to use Mouse.Target.Parent and Mouse.Target

Script

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local table1 = {game.Workspace.Folder.Part222, game.Workspace.Folder.Part111, game.Workspace.Folder.Part333}

mouse.Move:Connect(function()
	
	if mouse.Target.Parent == table1 then
		
		print("tad")
		
	end
	
end)

The table1 is a table.
The mouse.Target is a part.
They are not the same, you can’t do it like that.

You can do:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local table1 = {game.Workspace.Folder.Part222, game.Workspace.Folder.Part111, game.Workspace.Folder.Part333}

mouse.Move:Connect(function()
	
	if mouse.Target.Parent == table1[1] then
		
		print("tad")
		
	end
	
end)

I’m not too experienced with tables, but from what I know, it probably won’t work because you’re checking if the mouse’s target is any of the parts inside with just this line.

if mouse.Target.Parent == table1 then

Maybe try getting all the parts in the table and checking them one by one. Like so:

    for i = 1, #table1 do
    	if mouse.Target.Parent == table1[i] then
    		print("tad")
    	end
    end
1 Like

or he can do:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local table1 = {game.Workspace.Folder.Part222, game.Workspace.Folder.Part111, game.Workspace.Folder.Part333}

mouse.Move:Connect(function()
	
	if table1[mouse.Target.Parent] then
		
		print("tad")
		
	end
	
end)

This is the best solution I think.

1 Like

That is the best solution. Thanks for that.

I don’t know why but it is not working for me :confused:

Is there an error?
If there is, can you screenshot it or something?

No there are no errors I don’t know why is it now working

Try to print out the Target.

print(mouse.Target)

I tried it also but when I click it is not printing “tad”

I think I know what’s the issue.
You are checking if the Target.Parent is equal to X.
You need to check if the Target is equal to X

like:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local table1 = {game.Workspace.Folder.Part222, game.Workspace.Folder.Part111, game.Workspace.Folder.Part333}

mouse.Move:Connect(function()
	
	if table1[mouse.Target] then
		
		print("tad")
		
	end
	
end)

I tried
script
I also added print(mouse.Target)

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local table1 = {game.Workspace.Folder.Part222, game.Workspace.Folder.Part111, game.Workspace.Folder.Part333}

mouse.Move:Connect(function()
	
	if table1[mouse.Target] then
		
		print("tad")
		
	end
	
end)

The target but not the “tad” everything but not the “tad” if my mouse’s target was the part from the table

Then try @l1u2i3’s solution.

IT IS WORKING :smiley:
(some character to hit the limit)

2 Likes

Oh, I’m glad it worked for you! :smiley: