Glitchy Custom Rig

Hey guys! I’m trying to make an alpaca ai, but it seems to glitch the game. Does anyone know how to fix this?

while wait() do
	if humanoid.Health > 0 then
		if target and hasweapon(character) then
			stop = true
			spawn(function()
				if target then
					stop = false
					goto(target.PrimaryPart.Position + Vector3.new(math.random(-3,3),0,math.random(-3,3)))
				end
			end)
			spawn(function()
				if target and hasweapon(character) and canswing and (target.PrimaryPart.Position-root.Position).Magnitude <= 8 then
					canswing = false
					swing:Play()
					local weapon = getweapon()
					local candmg = true
					local hitalpacas = {}
					local dmg = weapon.Blade.Touched:Connect(function(hit)
						if hit.Parent.Parent == workspace.Alpacas and candmg and not table.find(hitalpacas, hit.Parent) then
							candmg = false
							table.insert(hitalpacas, hit.Parent)
							local armor = hasarmor(hit.Parent)
							if armor then
								hit.Parent:FindFirstChild("Humanoid").Health -= weapon:GetAttribute("damage") * armor:GetAttribute("absorption")
								armor:SetAttribute("durability", armor:GetAttribute("durability") - math.round(100/weapon:GetAttribute("damage")))
							else
								hit.Parent:FindFirstChild("Humanoid").Health -= weapon:GetAttribute("damage")
							end
							wait(.1)
							candmg = true
						end
					end)
					wait(.1)
					canswing = true
					dmg:Disconnect()
				end
			end)
			if target.Humanoid.Health == 0 then
				local nearalpacas = getnear()
				if #nearalpacas > 0 then
					target = nearalpacas[1]
				else
					target = nil
				end
			end
		else
			if hasweapon(character) then
				local nearalpacas = getnear()
				if #nearalpacas > 0 then
					target = nearalpacas[1]
				end
			else
				target = nil
			end
			if not target then
				goal = Vector3.new(math.random(-100,100),0,math.random(-100,100))
				goto(goal)
			end
		end
	else
		break
	end
end

1 Like

Update: I still dont have it fixed, but there is progress.
It is the swords that are affecting it, not the script. I’m not sure why, so if anyone knows how to fix it, it will be great!

Bump? I really need help. Tryingtogetthisto30char

What am I looking at here.

Is the alpaca AI not attacking other alpacas? If so, try adding print() in every if, else, and elseif statement that you have in the script.

1 Like

The ai is attacking other alpacas, just when the alpacas have a sword, it is wobbling. Ik this shouldn’t be in scripting support because I just found out it isn’t a scripting problem, but I don’t know how to fix it.

Does it still attack the alpacas when they have a sword and is also wobbling? Or is it just not working at all.

1 Like

The code is fine, just it wobbles alot if It has the sword.

Try enabling the Massless property on all the sword parts:

image

They are all massless, can collide off, and I made the density .01 in custom properties

Can you try disabling CanQuery and CanTouch as well?

I need cantouch for hit detection and I have no idea what canquery does. I fixed the turning, but now the animations glitch out (they rubberband)

Ok so basically my fix doesn’t “solve” the problem, because it is unrelated. The problem with the rotation was that I was calling “MoveTo” too fast, but it still is super laggy. How do I fix this?

I found a zombie ai made by y3llow mustang. I repurposed it and it works!