How do i return a variable inside a function that is inside an if statement

its not finding i removed it and it errored it said attempt to call nil val

fixed it it just prints nil nil nil

which line?
Because it’s one of the reason the code isn’t working
Pcall isn’t solving anything

What do you expect when you aren’t giving it any arguments?

dude im giving it arguments im returning 3 values

local Occupied, EnemyHumanoid, EnemyHMR = FindTarget.FindEnemy()

Where are the arguments?

	local Occupied, EnemyHumanoid, EnemyHMR = FindTarget.FindEnemy(TowerHumanoid,TowerTorso,Range,“Auto”)

This will work

local module = {

FindEnemy = function(TowerHumanoid,TowerTorso,Range,Type)
	local Occupied = false
	local EnemyHumanoid 
	local EnemyHMR 		
	
	for i,v in pairs(game.Workspace.Rigs.Zombies:GetChildren()) do
		EnemyHumanoid = v:FindFirstChild("Humanoid")
		EnemyHMR = v:FindFirstChild("HumanoidRootPart")
		if EnemyHumanoid then
			if Type == "Auto" and (TowerTorso.Position - EnemyHMR.Position).magnitude <= Range then
				print("FoundEnemy")
				if not Occupied then
					Occupied = true
					EnemyHMR.DescendantRemoving:Connect(function()
						Occupied = false
					end)
				else 
					break
				end
			elseif Type == "SemiAuto" and (TowerTorso.Position - EnemyHMR.Position).magnitude <= Range then
				print("FoundEnemy")		
			end
		elseif (TowerTorso.Position - EnemyHMR.Position).magnitude > Range then
			Occupied = false
		end			
	end
		
	if Occupied then 
		print("Returning")
		return Occupied,  EnemyHumanoid, EnemyHMR 
	end
end

}

return module

while wait() do
pcall(function()
local Occupied, EnemyHumanoid, EnemyHMR = FindTarget.FindEnemy()
FindTarget.FindEnemy(TowerHumanoid,TowerTorso,Range,“Auto”)
print(FindTarget.FindEnemy())
if EnemyHumanoid then
PlasmaRay.Transparency = 0.1
Dist = (TowerTorso.Position - EnemyHMR.Position).magnitude
PlasmaRay.CFrame = CFrame.new(script.Parent:WaitForChild(“PlasmaGun”):WaitForChild(“Spinner”):WaitForChild(“Start”).WorldPosition,EnemyHMR.Position)*CFrame.new(0,0,-Dist/2)
PlasmaRay.Size = Vector3.new(0.1,0.1,Dist)
TowerHMR.CFrame = CFrame.lookAt(TowerHMR.Position,Vector3.new(EnemyHMR.Position.X,TowerHMR.Position.Y,EnemyHMR.Position.Z)) * CFrame.Angles(0,0,0)
PlayStance:Stop()
PlayAttack:Play()
EnemyHumanoid:TakeDamage(20)
script.Parent:WaitForChild(“DamageDealt”).Value += 1
game.ServerStorage.GiveMoney:Fire(1)
script.Parent:WaitForChild(“PlasmaGun”):WaitForChild(“PlasmaBall”).Transparency = 0.8
elseif Occupied == false then
PlasmaRay.Transparency = 1
script.Parent:WaitForChild(“PlasmaGun”):WaitForChild(“PlasmaBall”).Transparency = 1
PlayAttack:Stop()
PlayStance:Play()
end

	TowerTorso:WaitForChild("Info"):WaitForChild("Frame"):WaitForChild("Top"):WaitForChild("TotalDamage").Text = "DMG: "..script.Parent:WaitForChild("DamageDealt").Value
	TowerTorso:WaitForChild("Info"):WaitForChild("Frame"):WaitForChild("Top"):WaitForChild("TowerName").Text =  script.Parent:WaitForChild("TowerName").Value
	TowerTorso:WaitForChild("Info"):WaitForChild("Frame"):WaitForChild("Bottom"):WaitForChild("Owner").Text =  script.Parent:WaitForChild("Owner").Value
end)

end

here

Just replace this piece of code without arguments and paste

local Occupied, EnemyHumanoid, EnemyHMR = FindTarget.FindEnemy(TowerHumanoid,TowerTorso,Range,“Auto”)

dude im passing args there and returning it

Maybe you could just me a screenshot of your code?
image
Like this