Setting humanoid's front and back

I got a script that basically finds the nearest player and moves the humanoid in direction of that player. It works fine with a normal dummy, problem is that when i made custom humanoid, its going in the direction of the player but its not facing it.

local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")
local dp = require(ServerScriptService.ItemTables)

local humanoid = script.Parent
local root = humanoid.Parent.PrimaryPart
local dzwiek = game:GetService("SoundService")
local targetDistance = 20
local stopDistance = 10
local damage = 5
local attackDistance = 10
local attackWait = 2
local lastAttack = tick()

function findNearestPlayer()
	local playerlist = Players:GetPlayers()

	local nearestPlayer = nil
	local distance = nil
	local direction = nil

	for _, player in pairs(playerlist) do
		local character = player.Character or player.CharacterAdded:Wait()
		local distanceVector = character.HumanoidRootPart.Position - root.Position
		if not nearestPlayer then
			nearestPlayer = player
			distance = distanceVector.Magnitude
			direction = distanceVector.Unit
		elseif distanceVector.Magnitude < distance then
			nearestPlayer = player
			distance = distanceVector.Magnitude
			direction = distanceVector.Unit

	return nearestPlayer, distance, direction

	local nearestPlayer, distance, direction = findNearestPlayer()
	if nearestPlayer then
		if distance <= targetDistance and distance > stopDistance then

		if distance <= attackDistance and tick() - lastAttack >=attackWait then
			lastAttack = tick()
			nearestPlayer.Character.Humanoid.Health -= damage

This is my script

You need to rotate the parts in your model so that it faces the correct way. Rotating the model itself will not work because that will be changed by the :Move function. Rotate the children of the model.

1 Like

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