Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

can't get the player's Humanoid using Touched function inside a script?

So i've got a script in a Mob and what that script does is get the humanoid when a part is touched, but the problem is that i'm using a Touched function and it can't get the humanoid

The player has other models with parts in it (armor made out of parts)

The script:

script.Parent.Damage.Touched:Connect(function(Hit)

Hum = Hit.Parent:FindFirstChild("Humanoid") or Hit.Parent.Parent:FindFirstChild("Humanoid")

if Hum ~= nil then
print("Hum found")
end

1 comment

0

Please indent your code properly. Even if it's only two lines your code should always be indented properly. Also, the function is called "print", not "Print".

1 answer

All parts of the avatar are parented under the Character. Use this code:

if Hit.Parent:FindFirstChild("Humanoid") then
	print("Humanoid Found")
end

You're attempting to set a variable to 2 options. That doesn't work. And it will still print even if it doesn't find it.

For extra help, please contact me on Discord.

Bark#4260

3 comments

0

"You're attempting to set a variable to 2 options. That doesn't work. And it will still print even if it doesn't find it." This is false. OP use "or", so if the first option is nil or falsey, it will go to the next one, hopefully it is not nil or it is truthy.

0

The problem is that it cant find the humanoid not thar it is printing

0

And the Parts are in another model inside the character

This discussion is preserved as it was. New answers, comments, and votes are closed.