I need help getting the player's torso

So I’m trying to make an enemy AI, but I’m not sure how to get the player’s torso from the AI’s character using a server script. How should I do this?

How would you want to get the player’s torso? Do just want to have it when they join the game, or when they touch your enemy?

It would get their humanoid and torso when they join, and then attack later on. This is my current code:

Players.PlayerAdded:Connect(function(player)
	local  plr = player.Character
end)
while true do wait(.1)
	local findPlrHum = plr:WaitForChild("Humanoid")
	local findPlrTorso = plr:FindFirstChild("Torso")
	plrHum = findPlrHum
	plrTorso = findPlrTorso
end

You have to put the while loop in the Players.PlayerAdded, here is the new code

Players.PlayerAdded:Connect(function(player)
	local  plr = player.Character
        while true do wait(.1)
	  local findPlrHum = plr:WaitForChild("Humanoid")
	  local findPlrTorso = plr:FindFirstChild("Torso")
	  plrHum = findPlrHum
	  plrTorso = findPlrTorso
end

end)
4 Likes

Thanks! I’ve been trying to find a solution for 2 weeks lol

3 Likes