How to find random humanoid across workspace

Hello! I am making a script where it will find one humanoid across workspace however I can’t find a way to make this work. I feel like this is a pretty easy thing to script but, I can’t figure it out. The closest code I could make is this:

for i,v in pairs(workspace:GetDescendants()) do
	if v:FindFirstChildOfClass("Humanoid") then
		if v:FindFirstChild("Head") then
		script.Parent.ViewCharacter.Value = v.Name
		end
		end
end


Which would find the first humanoid for some reason, Can someone help me?

local Humanoids = {}
for _, v in ipairs(game.Workspace:GetDescendants()) do
	if v.Class == "Humanoid" then
		table.insert(Humanoids, v)
	end
end

local randomHumanoid = Humanoids[math.random(1,#Humanoids)]
1 Like

Is the humanoid a player? If its a player u could just go into the game.Players and then get a random player from there and get the humanoid from the player.

Or just do what @SeargentAUS stated.