mouse.Target Help

hey there, i’m working on a test world, I have two tools, one of them makes new parts, then the seconds destroys them, first I went with this for the delete tool:

local Workspace = game:GetService("Workspace")
local Tool = script.Parent

local function Clicked()
    Part = Workspace:WaitForChild("Part")
end)
Tool.Activated:Connect(function()

this worked, but I wanted to give the player to have the option to delete the part of their choice, like in build tools

so I came up with this

local Tool = script.Parent
local Workspace = game:GetService(“Workspace”)

Tool.Equipped:Connect(function(mouse)
mouse.Button1Down:Connect(function()
	if mouse.target == workspace.Part then
		print(mouse.Target)
		mouse.Target:Destroy()
	end
    end)
end)

but I doesn’t work, no errors either

thanks in advance

1 Like

One immediate issue with this, is that this will not replicate across the client-server boundary. You would need to perform these actions on the server after handling the input on the client e.g. instantiating parts or removing them.

Also, I’m slightly confused by your equals operation:

if mouse.Target == workspace.Part then

Surely if one of the tools creates a new part, that Part may differ from the one you’re referencing with workspace.Part - you should instead check to see if it matches any other criteria e.g. a name, or a value as a child of the part that determines who placed that block.

Edit: also, it’s .Target - it’s case sensitive

1 Like

Try doing a mouse.Target.Name == "Name here", like @Isocortex suggested.

1 Like

Workspace is deprecated – you should use workspace.

You are comparing mouse.target (note the lowercase) to a Part instead of mouse.Target.

sorry, don’t get what you mean

You need to be a little more descriptive as to what exactly you don’t understand if you need help

doesn’t matter, read through it now, I understand

okay, now I need more help, when I test the game, my mouse disappears from the test screen so I can’t see where it is, I have been messing around with changing the mouses image, but I removed that script now.