Mouse Target not working

i want to do an action when mouse target is the parts that is in the folder and for some reason its not working

image

image

its printing the else part:
image

image

1 Like

You should get the parent rather than… actually I’m not sure what that is you tried doing.

1 Like

You can’t compare string to array you should use for loop.

1 Like

i have tried to do that its not worked either

image
image

Instead of doing

if mouse.Target.Name == PartsFolder:GetChildren().Name then

You should do:

for i, v in pairs(PartsFolder:GetChildren()) do
    if mouse.Target.Parent == v.Parent then -- Parent would be better. You never know
                                         --when something might have the same name.
          -- do what you want to do here
    end 
end

If this hasn’t worked, try printing out Mouse.Targert.Name

1 Like

Use this instead:

local function isValidPart()
    for _, child in pairs(PartsFolder:GetChildren()) do
        if mouse.Target.Name == child.Name then
            return true
        end
    end

    return false
end

if isValidPart() then
    --do stuff
end
if Mouse.Target then -- Check if the Target Actually Exists
   if Mouse.Target:IsDecendantOf(PartsFolder) then
      -- The Part is inside the folder and was clicked
      -- do what you want to do with the part
   end
end
1 Like