Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
UEm1R 9
6 years ago
Edited 6 years ago

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
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". User#19524 175 — 6y

1 answer

Log in to vote
-2
Answered by 6 years ago

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

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. User#19524 175 — 6y
0
The problem is that it cant find the humanoid not thar it is printing UEm1R 9 — 6y
0
And the Parts are in another model inside the character UEm1R 9 — 6y
Ad

Answer this question