NPC humanoid state stuck on freefalling state

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Fixing this bug so I can play animations on the NPC properly.

  2. What is the issue? As the title of this post.

  3. What solutions have you tried so far? I’ve been looking for solutions in the devforums for about an hour now, the only solution I thought about is disabling a part of a code “:SetNetworkOwnership(nil)”.

1 Like

What is your script? So I can know more

This is the entire script:

local players = game:GetService("Players")
local runServ = game:GetService("RunService")

local bot = script.Parent.Parent
local bot2 = script.Parent
local hum = bot:WaitForChild("bot")
local animCont = bot2:WaitForChild("AnimationController")

local player = nil
local maxDist = 100

local animInfo = {
	idle = { anim = script.Idle, weight = 1 },
	idle2 = { anim = script.LookAround, weight = 2 },
	attack = { anim = script.Attack, weight = 2 },
	run = { anim = script.Run, weight = 10 },
	runclose = { anim = script.RunClose, weight = 15 },
	walk = { anim = script.Walk, weight = 5 },
}

local anims = {
	idle = animCont:LoadAnimation(animInfo.idle.anim),
	idle2 = animCont:LoadAnimation(animInfo.idle2.anim),
	attack = animCont:LoadAnimation(animInfo.attack.anim),
	run = animCont:LoadAnimation(animInfo.run.anim),
	runclose = animCont:LoadAnimation(animInfo.runclose.anim),
	walk = animCont:LoadAnimation(animInfo.walk.anim),
}

anims.idle.Looped = true
anims.idle.Priority = Enum.AnimationPriority.Core
anims.idle2.Looped = false
anims.idle2.Priority = Enum.AnimationPriority.Core
anims.attack.Looped = false
anims.attack.Priority = Enum.AnimationPriority.Action
anims.run.Looped = true
anims.run.Priority = Enum.AnimationPriority.Movement
anims.runclose.Looped = true
anims.runclose.Priority = Enum.AnimationPriority.Movement
anims.walk.Looped = true
anims.walk.Priority = Enum.AnimationPriority.Idle

local function nearestPlr()
	local nearestPlayer, nearestDistance
	
	for _, player in pairs(players:GetPlayers()) do
		local character = player.Character
		local distance = player:DistanceFromCharacter(bot.HumanoidRootPart.Position)
		
		if not character or 
			distance > maxDist or
			(nearestDistance and distance >= nearestDistance)
		then
			continue
		end
		
		nearestDistance = distance
		nearestPlayer = player
	end
	--print("The nearest player is ", nearestPlayer)
	task.wait(0)
	player = nearestPlayer
end

local function playAnim(a, ts)
	if not anims[a].IsPlaying then
		anims[a]:Play(0.2)
	end
end

function stopAnim(a)
	if anims[a].IsPlaying then
		anims[a]:Stop(0.2)
	end
end

hum.StateChanged:Connect(function(old, new)
	if hum:GetState() ~= Enum.HumanoidStateType.Dead then
		if new == Enum.HumanoidStateType.Jumping then
			playAnim("attack")
		end
	end
end)

r = Random.new()
d = false
sp2 = 0

hum.Running:Connect(function(sp)
	print(sp)
	sp2 = sp
	
	if hum:GetState() ~= Enum.HumanoidStateType.Dead then
		stopAnim("walk")
		stopAnim("run")
		stopAnim("runclose")
		playAnim("idle")
		
		if hum:GetState() ~= Enum.HumanoidStateType.Freefall then
			playAnim("attack")
		elseif hum:GetState() ~= Enum.HumanoidStateType.Jumping then
			playAnim("attack")
		end
		
		if sp > 0 then
			stopAnim("walk")
			playAnim("run")
		end
	end
end)

runServ.Heartbeat:Connect(function(dt)
	if player ~= nil then 
		local dist = (player.Character:FindFirstChild("HumanoidRootPart").Position - bot.HumanoidRootPart.Position).Magnitude

		if sp2 > 40 then
			if dist <= 20 then
				playAnim("runclose")
			else
				stopAnim("runclose")
			end
		end
	end
end)

spawn(function()
	while task.wait(r:NextNumber(5, 20)) do
		if not d and hum:GetState() ~= Enum.HumanoidStateType.Freefall and hum:GetState() ~= Enum.HumanoidStateType.Jumping and hum:GetState() ~= Enum.HumanoidStateType.Climbing then
			playAnim("idle2")
		end
	end
end)

spawn(function()
	while task.wait(0) do
		nearestPlr()
	end
end)

all server sided btw

Nevermind, fixed the problem

HumanoidRootPart was in the air and the Humanoid HipHeight was set to 0

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