How can I make BasePart.Touched(Hit) ignore a player?

I’m trying to made a beam that stops when it collides with a part, but i want it to keep going if it touches a player, I’ve tried doing,

if not Hit.Parent:FindFirstChild("Humanoid") then

    print("Did not hit player")


That inside of the Touched function of course, but that does’t seem to work.
Any suggestions??

That will just ignore NPCs too.

Roblox has a function named, game.Players:GetPlayerFromCharacter()
Put this inside the touched function.

local player = game.Players:GetPlayerFromCharacter(hit.Parent) -- gets a player from their character
if player then -- YOU FOUND A PLAYER!
    print("Got player.")
    -- rest of code.
    print("Did not hit player.")
    return -- stops the code.
1 Like

Can I do something like:

if not player then
    --rest of the code

Of course, you can check if it’s not a player straight away.

1 Like