How to detect the player here

Hey guys, i have this sound jumpscare script and it worked just fine, but now that i just added a walking enemy npc i realized that when it touches the parts he triggers the jumpscares as if it was a player due to the script looking for a humanoid. Im trying to change the condition for it to detect it is a player and not the npc to play the sound, anyone know how to do it? I tried changing it but theres no error and sound doesnt play.

local character = script.Parent --The player
local humanoid = character:FindFirstChild("Humanoid")


local played = false
local played1 = false
local played2 = false
local played3 = false
local played4 = false

workspace.JumpscaresChapter1:FindFirstChild("JumpscareChurch").Touched:Connect(function(hit) --Which jumpscare we coding
	if played == false and hit.Parent == humanoid then
		workspace.JumpscaresChapter1:FindFirstChild("GlassBreak"):Play() --these are Sounds and The Folder in the workspace
		played = true --This disables the playing

Im not sure how to fix it. I also realized the NPC could trigger the sounds multiple times for some reason.

If humanoid.Parent ~= Monster then
—run the code
End

It complicated. :grimacing: :upside_down_face:

############

OnTouch will also fire multiple times when a player (humanoid) touches your Part.
Put a Debounce Patterns | Roblox Creator Documentation in your script.

How’s it going, there’s a function derived in game:GetService(“Players”) called :GetPlayerFromCharacter()
To go about the way you wish to do it, you’d simply do;

local FoundTarget = Hit:FindFirstAncestorOfClass("Model")

if FoundTarget and FoundTarget:FindFirstChildWhichIsA("Humanoid") then
    local FoundPlayer = game.Players:GetPlayerFromCharacter(FoundTarget)

    if FoundPlayer then
     -- // Do your code here or edit whatever.
    end
end

Now, you also posed the issue that it fires multiple times, you’d need a debounce (cooldown) because .Touched is fired LITERALLY every time a part is touched except if the touching part is not moving. I won’t spoonfeed code on debounces, so I’ll make ya look for it yourself, but other than that, it should work. Best of luck!

all you have to do is this

local character = script.Parent --The player
local humanoid = character:FindFirstChild("Humanoid")


local played = false
local played1 = false
local played2 = false
local played3 = false
local played4 = false

workspace.JumpscaresChapter1:FindFirstChild("JumpscareChurch").Touched:Connect(function(hit) 
if game.Players:FindFirstChild(character.Name)then 
	if played == false and hit.Parent == humanoid then
		workspace.JumpscaresChapter1:FindFirstChild("GlassBreak"):Play() --these are Sounds and The Folder in the workspace
		played = true --This disables the playing
end
end)

Thanks i tried this and worked on the debounce and it works fine now!