My NPC periodically stops rotating unless I move it with studio tools?

I have an npc that uses a bodygyro’s CFrame to aim at the player.
but periodically it just stops rotating and becomes unresponsive, I tried making the Y axis INF, I tried making every part as light as possible, and I tried getting rid of friction for both the NPC and the baseplate, but not matter what it wont rotate again UNLESS I move it up a little with the studio tools:
(excuse the quality as I had to use an online GIF converter)
ExampleVid

it was rotating before getting stuck so its not anchored or welded in any way.
is there a way to fix this? I want to use a bodygyro mover so that it moves smoothly unlike using CFrame.

can you give me the file???

Maybe try making it have a body position above the ground, maybe it will turn then.

Why should he just give you the file. I think it would be more appropriate to ask for the code, that is causing the “error”.

1 Like

true, heres the code:

function aim()
	if script.Parent.Parent.IsAttacking.Value == true then
	local t = script.Parent.Parent.Target.Value
	if t then
		local c = script.Parent.Parent.Parent.Parent.Center
		if c then
			c.BodyAim.CFrame = CFrame.new(c.Position,t.Position)
		end
	end
	end
end


while true do
	wait(0.1)
	aim()
end

the characters torso is in an object value. and all the script really does is set the body gyro’s CFrame to the torso’s position.

1 Like
local BodyPosition = Instance.new("BodyPosition", c)
BodyPosition.Position = c.Position

make sure it is above the ground or make the feet or the thing CanCollide = false.

1 Like

Also you should maybe do

while wait() do
       aim()
end

because it doesn’t wait as long as that while true do and if you were to remove that wait(0.1) then roblox studio might mess up

even suspended in mid air it still will periodically stop. :frowning:

there’s gotta be something wrong with the bodygyro for it to behave this way. maybe a bug?

Maybe. I will attempt to fix the script for you.

Is it just the script you put here?

yea, that and the GIF provided at the top of the post.

the red part is the aiming thing

(Not trying to mini-mod)
You can use the edit button to prevent unnecessary bumps

1 Like

Don’t use the parent argument of Instance.new, considering you’re setting a property after creating the object and parenting it.

I should have mentioned that my npc is non-humanoid, but thats ok because what you provided does help me go in the right direction so im just gonna go ahead and mark it as the solution. but I do have one last question.

in your code your getting the children of the workspace in order to use .Magnitude for the npc’s range.
if there are a lot of objects in the workspace will this cause performance problems?

not sure, it is a free model script i used, then i fixed it up