How to find the Player from the Humanoid?

		Humanoid.Died:Connect(function()

This is part of a script I have, I have the humanoid, great. But I’d like to find the player’s team, which means having to find the player, so how should I find the player from this humanoid which has been found?

Get the player from it’s character.

game:GetService("Players"):GetPlayerFromCharacter(Humanoid.Parent)
1 Like

-- Function to find the Player from the Humanoid
function getPlayerFromHumanoid(humanoid)
    if humanoid and humanoid.Parent then
        local character = humanoid.Parent
        local players = game:GetService("Players")

        -- Iterate through all players to find the matching character
        for _, player in ipairs(players:GetPlayers()) do
            if player.Character == character then
                return player
            end
        end
    end

    return nil -- Return nil if no player is found
end

-- Example usage
local humanoid = script.Parent:FindFirstChild("Humanoid") -- Replace with your actual Humanoid reference
local player = getPlayerFromHumanoid(humanoid)

if player then
    print("Player found: " .. player.Name)
else
    print("No player found for this humanoid.")
end

1 Like

You are need player name add script maybe working

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.