Yielding Error - Aero Game Framework

Im making a weapon system for my game, and in the part where I require the script, now its giving me this error(im using Aero Game Framework):

  13:41:02.398 - attempt to yield across metamethod/C-call boundary
13:41:02.399 - Stack Begin
13:41:02.400 - Script 'Players.HDWC.PlayerScripts.Aero.Internal.AeroClient', Line 110 - index Gun
13:41:02.400 - Script 'Players.HDWC.PlayerScripts.Aero.Controllers.Gun', Line 19 - method UseGun
13:41:02.401 - Script 'Players.HDWC.PlayerScripts.Aero.Controllers.Main', Line 19 - upvalue func
13:41:02.401 - Script 'ReplicatedStorage.Aero.Internal.FastSpawn', Line 43
13:41:02.402 - Stack End

The module being required:

local Gun = {}
Gun.__index = Gun
local CURRENTFOV = 70

local require = require(game:GetService("ReplicatedStorage").Nevermore)

function lerp(a,b,t) return a * (1-t) + b * t end

function Gun.new(char, gun)
	
	
	
	local self = setmetatable({
		
		char = char;
		gun = gun;
		firing = false;
		fireDT = 0;
		
	}, Gun)
	
	
	self.gun.Parent = workspace
	self.mouse = game.Players.LocalPlayer:GetMouse()
	self.aiming = false
	self.config = require(gun.Configuration)
	
	
	return self
	
end

function Gun:update(dt)
	local hit, position
	if self.firing then
		self.firedt = self.firedt + dt
		if self.firedt > 60 / self.config.FireRate then
			hit, position = self:fire()
			self.firedt = 0
		end
	end
	
	if hit then
		return hit, position
	end
end

function Gun:SetAiming(tf)
	self.aiming = tf
	if tf then
		coroutine.wrap(function()
			local beginNum = game.Players.LocalPlayer.CameraMaxZoomDistance
			local beginFov = workspace.CurrentCamera.FieldOfView
			local zoom = game.Players.LocalPlayer
			local fov = workspace.CurrentCamera
			
			local targetFov = (self.config.FOV / 100) * CURRENTFOV
			local targetZoom = self.config.AimCameraDist
			
			local totalDT = 0
			
			while fov.FieldOfView > targetFov and self.aiming do
				local dt = game:GetService("RunService").RenderStepped:wait()
				totalDT = totalDT + dt
				fov.FieldOfView = lerp(beginFov, targetFov, totalDT / 0.3)
				zoom.CameraMinZoomDistance = lerp(beginNum, targetZoom, totalDT / 0.3)
				zoom.CameraMaxZoomDistance = lerp(beginNum, targetZoom, totalDT / 0.3)
			end
		end)()
	else
		coroutine.wrap(function()
			local beginNum = game.Players.LocalPlayer.CameraMaxZoomDistance
			local beginFov = workspace.CurrentCamera.FieldOfView
			local zoom = game.Players.LocalPlayer
			local fov = workspace.CurrentCamera
			
			local targetFov = CURRENTFOV
			local targetZoom = 14
			
			local totalDT = 0
			
			while fov.FieldOfView < targetFov and not self.aiming do
				local dt = game:GetService("RunService").RenderStepped:wait()
				totalDT = totalDT + dt
				fov.FieldOfView = lerp(beginFov, targetFov, totalDT / 0.3)
				zoom.CameraMinZoomDistance = lerp(beginNum, targetZoom, totalDT / 0.3)
				zoom.CameraMaxZoomDistance = lerp(beginNum, targetZoom, totalDT / 0.3)
			end
		end)()
	end
end

function Gun:SetFiring(tf)
	self.firing = tf;
	self.firedt = 0;
end

function Gun:fire()
	local cameraDist = game.Players.LocalPlayer.CameraMaxZoomDistance
	local ray = Ray.new(self.mouse.UnitRay.Origin + (self.mouse.UnitRay.Direction.Unit * cameraDist), self.mouse.UnitRay.Direction.Unit * 1000)
	local hit, position, surfacenormal
	
	local ignoreList = workspace.Tracers:GetDescendants()
	for _,v in pairs(self.char:GetDescendants()) do
		if v:IsA("BasePart") then
			table.insert(ignoreList,v)
		end
	end
	
	if self.config.UseFastCast then
		
	else
		hit, position, surfacenormal = workspace:FindPartOnRayWithIgnoreList(ray,ignoreList)
	end
	
	
	
	local magnitude = (position - ray.Origin).magnitude
	
	local clone = self.gun.BodyAttach.Fire:Clone()
	clone.Parent = self.gun.Muzzle
	clone:Play()
	
	coroutine.wrap(function()
		local totalT = magnitude / self.config.Velocity 
		local totaldt = 0
		local beginV3 = self.gun.Muzzle.Position
		local part = Instance.new("Part")
		part.Size =Vector3.new(0.1,0.1,8)
		part.Color = Color3.new(1,1,1)
		part.Anchored = true
		part.CanCollide = false
		part.CFrame = CFrame.new(beginV3, position)
		part.Parent = workspace.Tracers
		part.Material = Enum.Material.Neon
		
		
		
		
		while totaldt < totalT do
			local dt = game:GetService("RunService").RenderStepped:wait()
			totaldt = totaldt + dt
			part.Position = beginV3:Lerp(position, totaldt / totalT)
		end
		part:Destroy()
		local attach = Instance.new("Attachment")
		attach.CFrame = CFrame.new(position, position - surfacenormal)
		attach.Parent = workspace.Terrain
		local particleEffect = script.ParticleEmitter:Clone()
		particleEffect.Parent = attach
		wait(0.05)
		particleEffect.Enabled = false
		wait(1)
		particleEffect:Destroy()
		clone:Destroy()
	end)()
	
	return hit, position
end

return Gun

And the one requiring it:

function Gun.new(char, gun)
	
	
	
	local self = setmetatable({
		
		char = char;
		gun = gun;
		firing = false;
		fireDT = 0;
		
	}, Gun)
	
	
	self.gun.Parent = workspace
	self.mouse = game.Players.LocalPlayer:GetMouse()
	self.aiming = false
	self.config = require(gun.Configuration)
	
	
	return self
	
end

All help is valued!

1 Like

Your 2nd code snippet seems to be the first one instead of the Main controller.

1 Like

Oh yeah the gun controller and the module Gun are the same name. Probably should change that. Its the second script that is erroring. Main is a different one

I think the problem is that you are calling for a value that has not yet loaded in your metatable. Another thing that could be happening is that you are calling something that yields.

Here is a more detailed explanation:

The error is telling you that you are attempting to yield from within Lua code where there is some C function between the Lua code doing the yielding and the Lua code that resumed the coroutine. To hit this error, what you have to have done is call some C function from Lua, which calls back into Lua code, which then calls coroutine.yield()

So do you have any idea how to fix it. Because in the part were I it errors im just creating the metatable. Do you think something could be erroring there?

Experiment to find out what is yielding and avoid it in your metatable. In this case has something to do with either char or gun.

Ended up being the character. Just had to get it inside the gun module instead.

1 Like