return function(Character)
local GetNearestHumanoid = require(script.Parent.Parent.GetNearestHumanoid)
local EnemyTable = require(script.Parent).EnemyTable
local Humanoid = Character:FindFirstChild(“Humanoid”)
if Humanoid and Character.PrimaryPart then
local Target = GetNearestHumanoid(Character, EnemyTable)
if Target and Target.Parent and Target.Parent.PrimaryPart then
local Distance = (Target.Parent.PrimaryPart.Position - Character.PrimaryPart.Position).Magnitude
Humanoid:MoveTo(Target.Parent.PrimaryPart.Position, Target.Parent.PrimaryPart)
if Distance < 10 then
Humanoid.WalkSpeed = EnemyTable.WalkSpeed
else
Humanoid.WalkSpeed = EnemyTable.WalkSpeed * 1.5
end
end
end
end
can someone tell me how i can optimize this movement code, im making an rpg game