NPCs glitches and floats (:MoveTo() won't work)

I’ve been experiencing this bug for quite a while now… But it happens so rarely, I can almost never test to see if it’s fixed or not, what the cause might be, etc.

  1. What do you want to achieve? Fix the broken NPCs to walk normally like the others

  2. What is the issue? Sometimes (Very rarely) one of the NPCs can get stuck in the air right after spawn. Nothing is anchored, and there isn’t a single error.
    8a19242554dfee795f006e94de13fb1b

  3. What solutions have you tried so far? I’ve searched the entire dev forums for a solution, and the only thing I found remotely close to this issue was still left unsolved… So I’m here to ask for anyone’s help who might know what could be causing the issue.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

Here is how I spawn the NPCs

--create clone
local npc = rep.NPCs.TestNPC:Clone()
npc.Parent = spot.Visitors
local success = false
if npc:FindFirstChild("Humanoid") then--has humanoid
	local speed = rep.NPCs.TestNPC.Humanoid.WalkSpeed
	npc.Humanoid.WalkSpeed = math.random(speed*100*.75,speed*100*1.25)/100
	success = pcall(function()
		local id = friendIDs[math.random(1,#friendIDs)]
		npc.Name = game.Players:GetNameFromUserIdAsync(id)
		local desc = game.Players:GetHumanoidDescriptionFromUserId(id)
		npc.Humanoid:ApplyDescription(desc)
		for i,v in pairs(npc:GetChildren())do--destroy layered clothing
			if v:IsA("Accessory") then
				for i,t in pairs(layeredClothingClasses)do
					if v.AccessoryType == Enum.AccessoryType[t] then
						v:Destroy()
						break
					end
				end
			end
		end
	end)
end
if success then--successfuly set humanoid desc
	startWalk(points,npc)--walk function
	spawn(function()
		antiCollideCharacter(npc)--avoid walking into eachother
	end)
else--if not, destroy
	npc:Destroy()
end

Heres how I move them:

function startWalk(points,npc)
	local char = player.Character
	if dist > max then--destroy cuz walkpoint too far
		npc:Destroy()
	else
		local at = startPoint
		local human = npc:WaitForChild"Humanoid"

		local walk = human.Animator:LoadAnimation(npc.Anims.WalkAnim)
		local think = human.Animator:LoadAnimation(npc.Anims.Think)
		local sit = human.Animator:LoadAnimation(npc.Anims.SitAnim)

		npc:SetPrimaryPartCFrame(CFrame.new(at.Position+Vector3.new(0,human.HipHeight+npc.PrimaryPart.Size.Y/2-at.Size.Y/2+1,0)))
		wait()
		walk:Play(nil,nil,human.WalkSpeed/6)
		human.MoveToFinished:Connect(function(reached)
		end)
		human:MoveTo(at.Position)
	end
end

If anyone can help it would be very appreciated!

2 Likes

If it’s working for some humanoids then it might be an internal glitch with humanoids. You could also try debugging it by adding some prints before the humanoid’s :WaitForChild. Another solution IMO would be to make custom humanoids/npcs this is very easy to make and makes the game’s performance way smoother and very easy to control from your side (Retail Tycoon 2 and Theme Park Tycoon 2 uses this).

2 Likes

What would that “Internal glitch” with humanoid be? And yea a custom npc would probably help, but it’s the last glitch to fix to release my game, so don’t feel like re-doing the whole NPC code you know :sweat_smile: What would you suggest other than prints to try to resolve the glitch with humanoid? And if I do see a glitched one again, what should I try in-studio to try to find the issue? Check humanoid properties or smth?

First of all, you should change :SetPrimaryPartCFrame to :PivotTo instead . Also why do you have a wait() on there?

I’m assuming it’s nothing to do with spawning NPCs since it would of have been destroyed if the pcall went unsuccessful. So it’s definitely something to do with line 13 to 18 in the second codeblock. I would recommend trying to clean up that part. My only thought right now would be the humanoid:MoveTo being called while the character is still in the air and didn’t touch the ground yet. The calculations of the npc’s cframe might be wrong here.

1 Like

The existence of Humanoids.
But no seriously Humanoids are garbage in terms of anything, if something stops working in the Humanoid, your entire NPC system breaks with extra perfomance issues and unneeded functions AND weird undocumented behavior added as well™

2 Likes