How do I fix stuttery animations?

So, I’m making a monster, and he stutters when chasing and walking. It isn’t the animations problem but playing them. the chasing might be a pathfinding issue, but the walking isn’t.

code for animations (idc if anyone wants to use):

-- settings --
local walkingspeed = 9 -- if walkspeed is over this then they will run.


-- ignore --

local Figure = script.Parent

local Humanoid = Figure:WaitForChild("Humanoid")
local pose = "Standing"

local EMOTE_TRANSITION_TIME = 0.1

local userAnimateScaleRunSuccess, userAnimateScaleRunValue = pcall(function() return UserSettings():IsUserFeatureEnabled("UserAnimateScaleRun") end)
local userAnimateScaleRun = userAnimateScaleRunSuccess and userAnimateScaleRunValue

local function getRigScale()
	if userAnimateScaleRun then
		return Figure:GetScale()
	else
		return 1
	end
end

local currentAnim = ""
local currentAnimInstance = nil
local currentAnimTrack = nil
local currentAnimKeyframeHandler = nil
local currentAnimSpeed = 1.0
local animTable = {}
local animNames = { 
	idle = 	{	
		{ id = "http://www.roblox.com/asset/?id=180435571", weight = 9 },
		{ id = "http://www.roblox.com/asset/?id=180435792", weight = 1 }
	},
	walk = 	{ 	
		{ id = "http://www.roblox.com/asset/?id=180426354", weight = 10 } 
	}, 
	run = 	{
		{ id = "run.xml", weight = 10 } 
	}, 
	jump = 	{
		{ id = "http://www.roblox.com/asset/?id=125750702", weight = 10 } 
	}, 
	fall = 	{
		{ id = "http://www.roblox.com/asset/?id=180436148", weight = 10 } 
	}, 
	climb = {
		{ id = "http://www.roblox.com/asset/?id=180436334", weight = 10 } 
	}, 
	sit = 	{
		{ id = "http://www.roblox.com/asset/?id=178130996", weight = 10 } 
	},	
	toolnone = {
		{ id = "http://www.roblox.com/asset/?id=182393478", weight = 10 } 
	},
	toolslash = {
		{ id = "http://www.roblox.com/asset/?id=129967390", weight = 10 } 
		--				{ id = "slash.xml", weight = 10 } 
	},
	toollunge = {
		{ id = "http://www.roblox.com/asset/?id=129967478", weight = 10 } 
	},
	wave = {
		{ id = "http://www.roblox.com/asset/?id=128777973", weight = 10 } 
	},
	point = {
		{ id = "http://www.roblox.com/asset/?id=128853357", weight = 10 } 
	},
	dance1 = {
		{ id = "http://www.roblox.com/asset/?id=182435998", weight = 10 }, 
		{ id = "http://www.roblox.com/asset/?id=182491037", weight = 10 }, 
		{ id = "http://www.roblox.com/asset/?id=182491065", weight = 10 } 
	},
	dance2 = {
		{ id = "http://www.roblox.com/asset/?id=182436842", weight = 10 }, 
		{ id = "http://www.roblox.com/asset/?id=182491248", weight = 10 }, 
		{ id = "http://www.roblox.com/asset/?id=182491277", weight = 10 } 
	},
	dance3 = {
		{ id = "http://www.roblox.com/asset/?id=182436935", weight = 10 }, 
		{ id = "http://www.roblox.com/asset/?id=182491368", weight = 10 }, 
		{ id = "http://www.roblox.com/asset/?id=182491423", weight = 10 } 
	},
	laugh = {
		{ id = "http://www.roblox.com/asset/?id=129423131", weight = 10 } 
	},
	cheer = {
		{ id = "http://www.roblox.com/asset/?id=129423030", weight = 10 } 
	},
}
local dances = {"dance1", "dance2", "dance3"}

-- Existance in this list signifies that it is an emote, the value indicates if it is a looping emote
local emoteNames = { wave = false, point = false, dance1 = true, dance2 = true, dance3 = true, laugh = false, cheer = false}

function configureAnimationSet(name, fileList)
	if (animTable[name] ~= nil) then
		for _, connection in pairs(animTable[name].connections) do
			connection:disconnect()
		end
	end
	animTable[name] = {}
	animTable[name].count = 0
	animTable[name].totalWeight = 0	
	animTable[name].connections = {}

	-- check for config values
	local config = script:FindFirstChild(name)
	if (config ~= nil) then
		--		print("Loading anims " .. name)
		table.insert(animTable[name].connections, config.ChildAdded:connect(function(child) configureAnimationSet(name, fileList) end))
		table.insert(animTable[name].connections, config.ChildRemoved:connect(function(child) configureAnimationSet(name, fileList) end))
		local idx = 1
		for _, childPart in pairs(config:GetChildren()) do
			if (childPart:IsA("Animation")) then
				table.insert(animTable[name].connections, childPart.Changed:connect(function(property) configureAnimationSet(name, fileList) end))
				animTable[name][idx] = {}
				animTable[name][idx].anim = childPart
				local weightObject = childPart:FindFirstChild("Weight")
				if (weightObject == nil) then
					animTable[name][idx].weight = 1
				else
					animTable[name][idx].weight = weightObject.Value
				end
				animTable[name].count = animTable[name].count + 1
				animTable[name].totalWeight = animTable[name].totalWeight + animTable[name][idx].weight
				--			print(name .. " [" .. idx .. "] " .. animTable[name][idx].anim.AnimationId .. " (" .. animTable[name][idx].weight .. ")")
				idx = idx + 1
			end
		end
	end

	-- fallback to defaults
	if (animTable[name].count <= 0) then
		for idx, anim in pairs(fileList) do
			animTable[name][idx] = {}
			animTable[name][idx].anim = Instance.new("Animation")
			animTable[name][idx].anim.Name = name
			animTable[name][idx].anim.AnimationId = anim.id
			animTable[name][idx].weight = anim.weight
			animTable[name].count = animTable[name].count + 1
			animTable[name].totalWeight = animTable[name].totalWeight + anim.weight
			--			print(name .. " [" .. idx .. "] " .. anim.id .. " (" .. anim.weight .. ")")
		end
	end
end

-- Setup animation objects
function scriptChildModified(child)
	local fileList = animNames[child.Name]
	if (fileList ~= nil) then
		configureAnimationSet(child.Name, fileList)
	end	
end

script.ChildAdded:connect(scriptChildModified)
script.ChildRemoved:connect(scriptChildModified)

-- Clear any existing animation tracks
-- Fixes issue with characters that are moved in and out of the Workspace accumulating tracks
local animator = if Humanoid then Humanoid:FindFirstChildOfClass("Animator") else nil
if animator then
	local animTracks = animator:GetPlayingAnimationTracks()
	for i,track in ipairs(animTracks) do
		track:Stop(0)
		track:Destroy()
	end
end


for name, fileList in pairs(animNames) do 
	configureAnimationSet(name, fileList)
end	

-- ANIMATION

-- declarations
local toolAnim = "None"
local toolAnimTime = 0

local jumpAnimTime = 0
local jumpAnimDuration = 0.3

local toolTransitionTime = 0.1
local fallTransitionTime = 0.3
local jumpMaxLimbVelocity = 0.75
local StutterCancel = false

-- functions

function stopAllAnimations()
	local oldAnim = currentAnim

	-- return to idle if finishing an emote
	if (emoteNames[oldAnim] ~= nil and emoteNames[oldAnim] == false) then
		oldAnim = "idle"
	end

	currentAnim = ""
	currentAnimInstance = nil
	if (currentAnimKeyframeHandler ~= nil) then
		currentAnimKeyframeHandler:disconnect()
	end

	if (currentAnimTrack ~= nil) then
		currentAnimTrack:Stop()
		currentAnimTrack:Destroy()
		currentAnimTrack = nil
	end
	return oldAnim
end

function setAnimationSpeed(speed)
	if speed ~= currentAnimSpeed then
		currentAnimSpeed = speed
		currentAnimTrack:AdjustSpeed(currentAnimSpeed)
	end
end

function keyFrameReachedFunc(frameName)
	if (frameName == "End") then

		local repeatAnim = currentAnim
		-- return to idle if finishing an emote
		if (emoteNames[repeatAnim] ~= nil and emoteNames[repeatAnim] == false) then
			repeatAnim = "idle"
		end

		local animSpeed = currentAnimSpeed
		playAnimation(repeatAnim, 0.0, Humanoid)
		setAnimationSpeed(animSpeed)
	end
end

-- Preload animations
function playAnimation(animName, transitionTime, humanoid) 
	local roll = math.random(1, animTable[animName].totalWeight) 
	local origRoll = roll
	local idx = 1
	while (roll > animTable[animName][idx].weight) do
		roll = roll - animTable[animName][idx].weight
		idx = idx + 1
	end
	--		print(animName .. " " .. idx .. " [" .. origRoll .. "]")
	local anim = animTable[animName][idx].anim

	-- switch animation		
	if (anim ~= currentAnimInstance) and animName ~= "Animation1" and animName ~= "climb" then

		if (currentAnimTrack ~= nil) then
			currentAnimTrack:Stop(transitionTime)
			currentAnimTrack:Destroy()
		end
		
		currentAnimSpeed = 1.0

		-- load it to the humanoid; get AnimationTrack
		currentAnimTrack = humanoid:LoadAnimation(anim)
		currentAnimTrack.Priority = Enum.AnimationPriority.Core

		-- play the animation
		currentAnimTrack:Play(transitionTime)
		currentAnim = animName
		currentAnimInstance = anim

		-- set up keyframe name triggers
		if (currentAnimKeyframeHandler ~= nil) then
			currentAnimKeyframeHandler:disconnect()
		end
		currentAnimKeyframeHandler = currentAnimTrack.KeyframeReached:connect(keyFrameReachedFunc)

	end

end

-------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------

local toolAnimName = ""
local toolAnimTrack = nil
local toolAnimInstance = nil
local currentToolAnimKeyframeHandler = nil

function toolKeyFrameReachedFunc(frameName)
	if (frameName == "End") then
		--		print("Keyframe : ".. frameName)	
		playToolAnimation(toolAnimName, 0.0, Humanoid)
	end
end


function playToolAnimation(animName, transitionTime, humanoid, priority)	 

	local roll = math.random(1, animTable[animName].totalWeight) 
	local origRoll = roll
	local idx = 1
	while (roll > animTable[animName][idx].weight) do
		roll = roll - animTable[animName][idx].weight
		idx = idx + 1
	end
	--		print(animName .. " * " .. idx .. " [" .. origRoll .. "]")
	local anim = animTable[animName][idx].anim

	if (toolAnimInstance ~= anim) then

		if (toolAnimTrack ~= nil) then
			toolAnimTrack:Stop()
			toolAnimTrack:Destroy()
			transitionTime = 0
		end

		-- load it to the humanoid; get AnimationTrack
		toolAnimTrack = humanoid:LoadAnimation(anim)
		if priority then
			toolAnimTrack.Priority = priority
		end

		-- play the animation
		toolAnimTrack:Play(transitionTime)
		toolAnimName = animName
		toolAnimInstance = anim

		currentToolAnimKeyframeHandler = toolAnimTrack.KeyframeReached:connect(toolKeyFrameReachedFunc)
	end
end

function stopToolAnimations()
	local oldAnim = toolAnimName

	if (currentToolAnimKeyframeHandler ~= nil) then
		currentToolAnimKeyframeHandler:disconnect()
	end

	toolAnimName = ""
	toolAnimInstance = nil
	if (toolAnimTrack ~= nil) then
		toolAnimTrack:Stop()
		toolAnimTrack:Destroy()
		toolAnimTrack = nil
	end


	return oldAnim
end

-------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------


function onRunning(speed)
	speed /= getRigScale()
	if speed > 0.01 then
		if Humanoid.WalkSpeed <= walkingspeed then
			playAnimation("walk", 0.1, Humanoid)
		else
			playAnimation("run", 0.1, Humanoid)
		end
		if currentAnimInstance then
			--setAnimationSpeed(speed / 14.5)
		end
		pose = "Running"
	else
		if emoteNames[currentAnim] == nil then
			playAnimation("idle", 0.1, Humanoid)
			pose = "Standing"
		end
	end
end

function onDied()
	pose = "Dead"
end

function onJumping()
	playAnimation("jump", 0.1, Humanoid)
	jumpAnimTime = jumpAnimDuration
	pose = "Jumping"
end

function onClimbing(speed)
	speed /= getRigScale()

	playAnimation("climb", 0.1, Humanoid)
	setAnimationSpeed(speed / 12.0)
	pose = "Climbing"
end

function onGettingUp()
	pose = "GettingUp"
end

function onFreeFall()
	if (jumpAnimTime <= 0) then
		playAnimation("fall", fallTransitionTime, Humanoid)
	end
	pose = "FreeFall"
end

function onFallingDown()
	pose = "FallingDown"
end

function onSeated()
	pose = "Seated"
end

function onPlatformStanding()
	pose = "PlatformStanding"
end

function onSwimming(speed)
	if speed > 0 then
		pose = "Running"
	else
		pose = "Standing"
	end
end

function getTool()	
	for _, kid in ipairs(Figure:GetChildren()) do
		if kid.className == "Tool" then return kid end
	end
	return nil
end

function getToolAnim(tool)
	for _, c in ipairs(tool:GetChildren()) do
		if c.Name == "toolanim" and c.className == "StringValue" then
			return c
		end
	end
	return nil
end

function animateTool()

	if (toolAnim == "None") then
		playToolAnimation("toolnone", toolTransitionTime, Humanoid, Enum.AnimationPriority.Idle)
		return
	end

	if (toolAnim == "Slash") then
		playToolAnimation("toolslash", 0, Humanoid, Enum.AnimationPriority.Action)
		return
	end

	if (toolAnim == "Lunge") then
		playToolAnimation("toollunge", 0, Humanoid, Enum.AnimationPriority.Action)
		return
	end
end

function moveSit()
	
end

local lastTick = 0

function move(time)
	local amplitude = 1
	local frequency = 1
	local deltaTime = time - lastTick
	lastTick = time
	
	local climbFudge = 0
	local setAngles = false
	
	if (jumpAnimTime > 0) then
		jumpAnimTime = jumpAnimTime - deltaTime
	end

	if (pose == "FreeFall" and jumpAnimTime <= 0) then
		playAnimation("fall", fallTransitionTime, Humanoid)
	elseif (pose == "Seated") then
		playAnimation("sit", 0.5, Humanoid)
		return
	elseif (pose == "Running") then
		if Humanoid.WalkSpeed <= walkingspeed then
			playAnimation("walk", 0.1, Humanoid)
		else
			playAnimation("run", 0.1, Humanoid)
		end
	elseif (pose == "Dead" or pose == "GettingUp" or pose == "FallingDown" or pose == "Seated" or pose == "PlatformStanding") then
		--		print("Wha " .. pose)
		stopAllAnimations()
		amplitude = 0.1
		frequency = 1
		setAngles = true
	end

	if (setAngles) then
		local desiredAngle = amplitude * math.sin(time * frequency)

		
	end

	-- Tool Animation handling
	local tool = getTool()
	if tool and tool:FindFirstChild("Handle") then

		local animStringValueObject = getToolAnim(tool)

		if animStringValueObject then
			toolAnim = animStringValueObject.Value
			-- message recieved, delete StringValue
			animStringValueObject.Parent = nil
			toolAnimTime = time + .3
		end

		if time > toolAnimTime then
			toolAnimTime = 0
			toolAnim = "None"
		end

		animateTool()		
	else
		stopToolAnimations()
		toolAnim = "None"
		toolAnimInstance = nil
		toolAnimTime = 0
	end
end

-- connect events
Humanoid.Died:connect(onDied)
Humanoid.Running:connect(onRunning)
Humanoid.Jumping:connect(onJumping)
Humanoid.Climbing:connect(onClimbing)
Humanoid.GettingUp:connect(onGettingUp)
Humanoid.FreeFalling:connect(onFreeFall)
Humanoid.FallingDown:connect(onFallingDown)
Humanoid.Seated:connect(onSeated)
Humanoid.PlatformStanding:connect(onPlatformStanding)
Humanoid.Swimming:connect(onSwimming)

---- setup emote chat hook

-- main program

-- initialize to idle
playAnimation("idle", 0.1, Humanoid)
pose = "Standing"

while Figure.Parent ~= nil do
	local _, time = wait(0.1)
	move(time)
end

code for pathfind (don’t use this please):

-- settings --
local ViewDistance = 30
local ShortAttackDistance = 10
local FarAttackDistance = 20

local ChaseSpeed = 18
local WalkSpeed = 9

-------------------------
-------------------------

local Character = script.Parent
local Humanoid = Character.Humanoid
local RootPart = Humanoid.RootPart
local XOffset = Character.UpperTorso.Neck.C0.X
local YOffset = Character.UpperTorso.Neck.C0.Y
local ZOffset = Character.UpperTorso.Neck.C0.Z
local Values = script.Parent.Values

local LightSwingAnim = Humanoid:LoadAnimation(script.LightSwing)
LightSwingAnim.Priority = Enum.AnimationPriority.Action

local StunnedAnim = Humanoid:LoadAnimation(script.Stunned)
StunnedAnim.Priority = Enum.AnimationPriority.Action

local Hitbox
local HitboxFunction

local AttackCoolDown = 0
local Attacks = {
	Close = {
		Swing = function()
			AttackCoolDown += 1
			LightSwingAnim:Play()
			Character.HumanoidRootPart.Swing:Play()
			local Part = Instance.new("Part",workspace.YEAH)
			Part.Position = Character.LowerTorso.Position + (RootPart.CFrame.LookVector * 4); Part.CFrame = CFrame.lookAt(Part.Position,Character.LowerTorso.Position)
			Part.Size = Vector3.new(6,10,6)
			Part.Transparency = .5
			Part.CanCollide = false
			Part.Anchored = true
			Part.CanQuery = false
		end,
		Jump = function()
			print("ok")
		end,
	},
	Far = {
		
	},
}

local PathfindingService = game:GetService("PathfindingService")
local TweenService = game:GetService("TweenService")

local can = false
local MAX_RETRIES = 5
local RETRY_COOLDOWN = 5
local YIELDING = false
local Agentparams = {
	AgentRadius = 5,
	AgentHeight = 6,
	AgentCanClimb = false,
	AgentCanJump = false,
	WaypointSpacing = 5,
	Costs = {
		Water = 100,
		DangerZone = math.huge,
		Wall = 10,
	}
}


local path = PathfindingService:CreatePath(Agentparams)

local reachedConnection
local pathBlockedConnection
local moveto
local target
local lastseenpos


function Stare(Hrp,Stop)
	if Stop == true then
		Character.UpperTorso.Neck.C0 = CFrame.new(XOffset, YOffset, ZOffset) * CFrame.Angles(0,math.rad(180),0)
		return
	end
	local dist = (Hrp.Position - RootPart.Position).Magnitude
	local dir = (Hrp.Position - RootPart.Position).Unit
	local vecA = Vector2.new(RootPart.CFrame.LookVector.X, RootPart.CFrame.LookVector.Z)
	local vecB = Vector2.new(dir.X, dir.Z)
	local dotValue = vecA:Dot(vecB)
	local crossValue = vecA:Cross(vecB)
	local ht = RootPart.Position.Y - Hrp.Position.Y
	local upAngle = math.atan(ht/dist)

	local angle = math.atan2(crossValue, dotValue)
	if angle > math.pi/3 then
		angle = math.pi/3
	elseif angle < -math.pi/3 then
		angle = -math.pi/3
	end
	TweenService:Create(Character.UpperTorso.Neck,TweenInfo.new(.05),{C0 = CFrame.new(XOffset, YOffset, ZOffset) * CFrame.Angles(0, -angle + 160, 0) * CFrame.Angles(-upAngle + 50, 0, 0)}):Play()
end

local function WalkTo(Pos, yieldable, targetcancel)
	local RETRY_NUM = 0
	local success, errorMessage
	
	repeat
		RETRY_NUM += 1
		success, errorMessage = pcall(path.ComputeAsync, path, RootPart.Position, Pos)
		if not success then
			warn("Pathfind compute path error: "..errorMessage)
			task.wait(RETRY_COOLDOWN)
		end
	until success == true or RETRY_NUM > MAX_RETRIES
	
	if success then
		Values.Pathfinding.Value = true
		if path.Status == Enum.PathStatus.Success then
			local waypoints = path:GetWaypoints()
			local currentWaypointIndex = 2
			for _, Point in pairs(waypoints) do
				local Part = Instance.new("Part",workspace.YEAH)
				Part.Anchored = true
				Part.CanCollide = false
			end
			if not reachedConnection then
				reachedConnection = Humanoid.MoveToFinished:Connect(function(reached)
					if reached and currentWaypointIndex < #waypoints then
						currentWaypointIndex += 1
						Humanoid:MoveTo(waypoints[currentWaypointIndex].Position)
						if waypoints[currentWaypointIndex].Action == Enum.PathWaypointAction.Jump then
							Humanoid.Jump = true
						end
					else
						Values.Pathfinding.Value = false
						reachedConnection:Disconnect()
						pathBlockedConnection:Disconnect()
						reachedConnection = nil
						pathBlockedConnection = nil
						YIELDING = false
					end
				end)
			end

			pathBlockedConnection = path.Blocked:Connect(function(waypointNumber)
				if waypointNumber > currentWaypointIndex then
					if reachedConnection then
						reachedConnection:Disconnect()
					end
					if pathBlockedConnection then
						pathBlockedConnection:Disconnect()
					end
					reachedConnection = nil
					pathBlockedConnection = nil
					WalkTo(Pos, true)
				end
			end)
			Humanoid:MoveTo(waypoints[currentWaypointIndex].Position)
			if waypoints[currentWaypointIndex].Action == Enum.PathWaypointAction.Jump then
				Humanoid.Jump = true
			end

			if yieldable then
				YIELDING = true
				local Cancel
				repeat 
					task.wait()
					if targetcancel == true and target then
						Cancel = true
					end
				until YIELDING == false or Cancel == true
			end
		else
			Values.Pathfinding.Value = false
			return 
		end
	else
		Values.Pathfinding.Value = false
		warn("Pathfind compute retry maxed out, error: "..errorMessage)
		return
	end
end

function GetDodge()
	local character1Position = Character.HumanoidRootPart.Position
	local character2Position = target.HumanoidRootPart.Position

	local positionDifference = character2Position - character1Position 
	local normalizedDirection = positionDifference.unit 
		
	local RUN_DISTANCE = 10 
	local targetAvoidanceLocation = character1Position + normalizedDirection * -1 * RUN_DISTANCE
end

function Check()
	local Players = game.Players:GetPlayers()
	local List = {}
	for _, player in pairs(Players) do
		if player.Character then
			local Char = player.Character
			if (Char.HumanoidRootPart.Position - RootPart.Position).Magnitude < ViewDistance then
				local raycastParams = RaycastParams.new()
				raycastParams.FilterDescendantsInstances = {player.Character,Character}
				raycastParams.FilterType = Enum.RaycastFilterType.Exclude
				for _, player in pairs(game.Players:GetPlayers()) do
					if player.Character then
						table.insert(raycastParams.FilterDescendantsInstances,player.Character)
					end
				end
				local raycastResult = workspace:Raycast(script.Parent.Head.Position, Char.HumanoidRootPart.Position - RootPart.Position, raycastParams)
				if raycastResult == nil or target == Char then
					table.insert(List,player.Character)
				end
			end
		end
	end
	return List
end

function GetTargetInList(List)
	local Closets = nil
	for _, TempCharacter in pairs(List) do
		if TempCharacter.Humanoid.Health > 0 then
			if Closets == nil then
				Closets = TempCharacter
			elseif (TempCharacter.HumanoidRootPart.Position - RootPart.Position).Magnitude < (Closets.HumanoidRootPart.Position - RootPart.Position).Magnitude then
				Closets = TempCharacter
			end
		end
	end
	return Closets
end

function Wander(Yieldable)
	local Position = RootPart.Position + Vector3.new(math.random(-100,100),0,math.random(-100,100))
	WalkTo(Position,false)
	local TimedOut = false
	moveto = Humanoid.MoveToFinished:Connect(function(reached)
		if reached == false then
			TimedOut = true
			moveto:Disconnect()
		end
	end)
	if Yieldable then
		local nearby
		local TIME_OUT2 = 0
		repeat
			wait(.1)
			TIME_OUT2 += .1
			nearby = Check()
		until (Position - RootPart.Position).Magnitude < 10 or TimedOut == true or #nearby > 0 or TIME_OUT2 > 5
		if moveto then
			moveto:Disconnect()
		end
		if #nearby > 0 then
			return nearby
		else
			return false
		end
	end
end

function Raycast(Origin: Vector3, EndGoal: Vector3,Exclude)
	local TableParams = {Character}
	local raycastParams = RaycastParams.new()
	raycastParams.FilterDescendantsInstances = {Character}
	raycastParams.FilterType = Enum.RaycastFilterType.Exclude
	for _, player in pairs(game.Players:GetPlayers()) do
		if player.Character then
			table.insert(TableParams,player.Character)
		end
	end
	for _, player in pairs(Exclude) do
		table.insert(TableParams,player)
	end
	raycastParams.FilterDescendantsInstances = TableParams
	local Cast = workspace:Raycast(Origin,EndGoal - Origin,raycastParams)
	return Cast
end


while true do
	wait(.1)
	
	if AttackCoolDown > 0 then
		AttackCoolDown -= .1
	end
	local nearby
	if target == nil then
		Humanoid.WalkSpeed = WalkSpeed
		nearby = Wander(true)
		Stare(nil,true)
	end
	if nearby or target then
		if Values.StunTime.Value <= 0 then
			Humanoid.WalkSpeed = ChaseSpeed
		end
		if target == nil then
			--RootPart.Notice:Play()
		end
		local NewNearby = Check()
		target = GetTargetInList(NewNearby)
		if target then
			local cast = Raycast(RootPart.Position,target.HumanoidRootPart.Position,{target})
			Stare(target.Head)
			WalkTo(target.HumanoidRootPart.Position,false)
			if AttackCoolDown <= 0 then
				if (target.HumanoidRootPart.Position - Character.HumanoidRootPart.Position).Magnitude < ShortAttackDistance then
					local close = Attacks.Close
					local CloseMax = 0
					for _, V in pairs(close) do
						CloseMax += 1
					end
					local Index = 0
					for I, V in pairs(close) do
						Index += 1
						if Index == CloseMax then
							V()
						end
					end
				elseif (target.HumanoidRootPart.Position - Character.HumanoidRootPart.Position).Magnitude < FarAttackDistance then
				
				end
			end
		end
	end
	if Values.StunTime.Value > 0 then
		Values.StunTime.Value -= .1
		Humanoid.WalkSpeed = WalkSpeed
		if StunnedAnim.IsPlaying == false then
			StunnedAnim:Play()
		end
	else
		if StunnedAnim.IsPlaying == true then
			StunnedAnim:Stop()
		end
	end
end

type or paste code here