Getting The Humanoid

Hey Guys! I’ve been needing to ask a question for myself and some other people. I’m a beginner scripter that needs help with the ‘Humanoid’ part. I simply need to know how to get ‘Humanoid’ as a variable from a script.

My script is located in the WorkSpace area so It’s not in the players part.

Any help is greatly appreciated as I’ve looked over YouTube and the Roblox Developer website but cannot find anything to do with my exact topic.
Thanks :grinning:

It would be nice to have a bit of context, like what you plan on doing with the humanoid. You can get the humanoid of players who joined the game by doing this in the script:

game:GetService("Players").PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        local humanoid = character:WaitForChild("Humanoid")
        -- Do whatever you want to the humanoid here!
    end)
end)
1 Like

When they touch a part? Or…? We need more than “how to get the humanoid?”

There’s @Awesom3_Eric’s way of using PlayerAdded, there’s also using the Touched event, etc, be more specific

I want it so when they touch a part the function will trigger.

local part = script.Parent
local deb = false
part.Touched:Connect(function(hit)
    local hum = hit.Parent:FindFirstChild("Humanoid")
    if deb or not hum then return end
    deb = true
    print(hum.Health)
    wait(5)
    deb = false
end)

You can do that like this.

2 Likes

What if it were to simply change the transparency on hit?

local part = script.Parent
local deb = false
part.Touched:Connect(function(hit)
    local hum = hit.Parent:FindFirstChild("Humanoid")
    if deb or not hum then return end
    deb = true
    part.Transparency = 1 --CHANGE THIS
end)

Put this script inside the part

1 Like

Thanks! This was the soloution.