I have some ideas, but everything I try won't work. Any idea?
You need two things:
The first one is simple: if the part's parent has a humanoid AND game.Players:GetPlayerFromCharacter(target.Parent) returns something, you know it's a "character part".
function CheckPlayerPart(target) if target.Parent:FindFirstChild("Humanoid") then return game.Players:GetPlayerFromCharacter(target.Parent) ~= nil end return false end
To check if something is close, you can use a trick with positions. The "magnitude" of a vector returns the length of it - if you subtract the position of the player and the position of the part you get a new vector defining the offset of that player part: the length is the distance (this always is a positive value).
function GetInrange(part) return (part.Position - game.Players.LocalPlayer.Character.Torso.Position).magnitude >20 end
And to put it all together:
local mouse = game.Players.LocalPlayer:GetMouse() function Check(target) if not target then return false end return GetInrange(target) and CheckPlayerPart(target) end mouse.Button1Click:connect(function() if Check(mouse.Target) then -- do stuff end end)
You also need to provide - in the same script - the functions described above.