How do I exclude the player from a Touched event?

So what I’m trying to do is exclude the player from the touched event.

What the touched event does is makes a “fake raycast” which I have already set up and it works perfectly fine, although It does hit the player since it isn’t a ray. Is there anyway to exclude the “shooter” from the shot/hit/getting hit?

Are you using both Touched and raycast? It seems like you can use WorldRoot | Documentation - Roblox Creator Hub

or you can simply do if you are using touched

part.Touched:Connect(function(h)
    if h.Parent.Name == game.Players.LocalPlayer.Name then
        else
        -- code
    end
end)

You could use a variable to figure out what the player’s character is, and then do something like

if not partThatItHit.Parent == characterVariable then
    --do code
end

I have already tried this and there was no luck. and I only use the Touched event.

Share the code you tried, there are no reasons why the script wouldn’t work

I have already tried that too and there was also no luck.
BTW there is no point in doing if not *Insert thing* == *Insert other thing* then, you only need to do if *Insert thing* ~= *Insert other thing* then

True, forgot about that XD.

function FakeRayForGuns(Player, Hit, Damage)
if Hit ~= nil and Hit.Parent.Name ~= Player.Name then
    if Player.Character:FindFirstChild("LowerTorso") ~= nil then
        if Hit.Name == "Head" or Hit.Name == "Handle" then  -- Handle for accessories
            Hit.Parent:FindFirstChild("Humanoid").Health = Hit.Parent:FindFirstChild("Humanoid").Health - Damage
        end
    end
end
end

Yes, it is a function.
I call the function inside the .Touched event.

If you know the name of the player then inside the Touched event, return when the Hit.Parent’s name is equal to the player’s.

Im not so good with returning do you mind helping me with that part?

Inside the touched event, if hit.Parent.Name == excludedPlayer.Name then return end.

try this:

function FakeRayForGuns(Player, Hit, Damage)
    if Player.Name ~= Hit.Parent.Name then
        if Hit.Name == "Head" then
            Hit.Parent.Humanoid.Health = Hit.Parent.Humanoid.Health - Damage
        elseif Hit.Name == "Handle" then
            Hit.Parent.Humanoid.Health = Hit.Parent.Humanoid.Health - Damage
        end
    end
end

I rewrote your function, try and see if it works…

local player = -- player

part.Touched:Connect(function(part)
    if part.Parent ~= player.Character then
        -- code here
    end
end)

This will make it do nothing if the part is part of the player

Didn’t help much but I’ll still give you the solution mark for the best answer!