im making a npc ai, and im having a problem that one of the npcs works perfectly fine and the other one just spins like crazy, im using body gyro but it doesn't seems to work ?
here's my code
local crocs = true local cro = true local cr = false local function sue() if cr == true then return end local timeo = math.random(1,8) wait(timeo) cro = true cr = false end function lookAt(chr,target) --assume chr is a character and target is a brick to look towards if chr.PrimaryPart then --just make sure the character's HRP has loaded local chrPos=chr.PrimaryPart.Position --get the position of the HRP local tPos=target.Position --get the position of the target local modTPos=Vector3.new(tPos.X,chrPos.Y,tPos.X) --make a position at the target, but with the height of the character local newCF=CFrame.new(chrPos,modTPos) --create our CFrame chr:SetPrimaryPartCFrame(newCF) --set the HRP's CFrame to our result, thus moving the character! end end script.Parent.Target.Changed:Connect(function() if script.Parent.Target.Value ~= nil then crocs = false local target = script.Parent.Target.Value local myhuam = script.Parent.Humanoid while crocs == false do wait() sue() script.Parent.HumanoidRootPart.BodyGyro.CFrame = CFrame.new(script.Parent.Torso.Position - Vector3.new(0,script.Parent.Torso.Position.y,0),target.HumanoidRootPart.Position - Vector3.new(0,target.HumanoidRootPart.Position.y,0)) --script.Parent.HumanoidRootPart.BodyGyro.CFrame = CFrame.new(script.Parent.Torso.Position - Vector3.new(0,script.Parent.Torso.Position.y,0),target.HumanoidRootPart.Position - Vector3.new(0,target.HumanoidRootPart.Position.y,0)) cr = true local move = math.random(1,3) if cro then if move < 3 then local moto = math.random(-3,3) local offset = Vector3.new(moto,0,-8) local pos = target.Torso.CFrame*CFrame.new(offset).Position myhuam:MoveTo(pos) end end if not cro then if move == 3 then myhuam:MoveTo(target.Torso.Position) end end end else crocs = true end end)
and here's a gyazo gif of the problem
https://gyazo.com/950c7d5d8dea6f83aee73946b4e345dc
the MaxTorque of both body gyros are 0,10000,0 the P is 3000 and the D is 500