Getting the humanoid

Is there another way to get the Humanoid rather than using a touched event, playeradded event ect? I’m struggling to get the humanoid as i cant really use a player event in this occasion unless i can somehow use the playeradded event for an event in game. The script i want to use this in is in the workspace and is a normal script. Any help will be appreciated.

1 Like

Simple answer: Remote Events

The .Touched event returns the Instance who touched it.

local Part = script.Parent

Part.Touched:Connect(function(hit)
    local Humanoid = hit.Parent:FindFirstChild("Humanoid")

    if Humanoid then
        print("Humanoid found")
    else
        print("No Humanoid")
    end
end)

If you’d like to get the Humanoid by a PlayerAdded it would be like this:

game.Players.PlayerAdded:Connect(function(player)
    local Character = player.Character or player.CharacterAdded:Wait()
    local Humanoid = Character.Humanoid
end)
1 Like

i did look into remote events for this situation, but im not sure how to use it for finding the humanoid. (specifically the players in the game area, without affecting the players in the lobby area)

unfortunately i cant really use that in this situation, but i did try it

What is your goal? What are you doing that needs the Humanoid? This might help me answer.

i need to find the humanoid for StateType(), which im using to detect if a user is sitting or standing

You can get a humanoid anywhere a player instance is involved. If a player joins, setup a player added event, then setup a character added event then get the humanoid of the character added. Simple.

1 Like

Here is what I mean:

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		local humanoid = char:WaitForChild("Humanoid")
		-- you can do anything you want with the humanoid
	end)
end)

You’re using a local script or a server script?

If it’s a local script then its’s simple as this:

local player = game.Players.LocalPlayer
local character = player.Character

local humanoid = character.Humanoid

If it’s a server script I’m gonna look into another method.

You got to make sure there even is a character loaded and the humanoid is too.

i’m using a server script, unfortunately

What is your usecase, I see your trying to detect if a player is sitting but what are you try to do?

i cant use that due to the fact it will also find the lobby players’ humanoid

So your saying you have a lobby, and in-game correct? Do you have a piece of code that teleports all players to the in game area or do you have teams or bool values to let you know if the player is in-game.

If one of the second options are true you can loop through all players, check if they are in-game (based on team or bool value) get their character and humanoid

im trying to incorporate a simple hiding event in my game, by find if a player is sitting (hiding) or standing (not hiding)

On a seat or just anywhere???

im creating the events before i make the main bit of functioning game (intermissions, detecting a winner, and teleporting the lobby players to the in game area after the current game if finished ect)

Hey @shinzos_MT can you answer me this, it would help me a lot to help you.

on a seat part that is inside of the hiding object