Function not returning proper values

I am making a game where there is a function that runs everytime the ball hits a wall. I implimented an ability that allowed for the effect to trigger as it bounced and change it’s direction. The table returned by the bounce effects function is always the same: “[]” with no values input inside of it. Could anyone give me any suggestions?

Code samples:

Called function to calculate a bounce:

local function CALCULATE(ORIGIN, Blacklists)

instance where it calls the bounce effects function (from a separate module)

task.wait(Time)
BallMainData.LastHitter.Value = nil
	
local EXTRA = BallMainModule.BounceEffect()

at the end the calculate function recalls itself to continue the cycle:

CALCULATE(RayCast.Position, RayCast.Instance)

the bounce effect function looks like this:

moduleX.BounceEffect = function()
	local ReturnEffects = {}

	if Data.Effects:FindFirstChild("OrionSpeed") ~= nil then

		if tonumber(string.split(Data.Effects.OrionSpeed.Value,"~")[3]) == 1 or tonumber(string.split(Data.Effects.OrionSpeed.Value,"~")[3]) == nil then
			game.ReplicatedStorage.EVENTS.CLIENT.ClientEffect:FireAllClients("OrionSpeed", 3)
			Data.Effects["OrionSpeed"]:Destroy()
		elseif tonumber(string.split(Data.Effects.OrionSpeed.Value,"~")[3]) ~= nil then
			local Current = tonumber(string.split(Data.Effects.OrionSpeed.Value,"~")[3])
			local New = "DAMAGE~"..string.split(Data.Effects.OrionSpeed.Value,"~")[2].."~"..tostring(Current - 1)
			Data.Effects.OrionSpeed.Value = New
		end

	end

	if Data.Effects:FindFirstChild("BaseBallTarget") ~= nil then
		print("FOUND VALUE")
		local Candidate = nil
		local Closeness = math.huge

		for i, v in ipairs(workspace.Players:GetChildren()) do
			local PData = game.ReplicatedStorage.PLAYERDATA[v.Name]

			if PData.Team.Value ~= Data.Effects.BaseBallTarget.Value then
				local Dis = (v.HumanoidRootPart.Position - Data.Ball.Value.Position).Magnitude

				if Dis < Closeness then
					Closeness = Dis
					Candidate = v
				end
			end
		end

		print("CHECKED CAND")

		if Candidate ~= nil then
			print("FOUND CANDS")

			local DCF = CFrame.new(Data.Ball.Value.Position, Candidate.HumanoidRootPart.Position)

			local Direction = Vector3.new(DCF.X,DCF.Y,0)

			local InstanceTable = {
				Name = "NEWDIRECTION",
				Value = Direction,
			}

			table.insert(ReturnEffects, InstanceTable)
		end

		game.ReplicatedStorage.EVENTS.CLIENT.ClientEffect:FireAllClients("OrionSpeed", 3)
		Data.Effects.BaseBallTarget:Destroy()
	end
	
	for i, v in ipairs(ReturnEffects) do
		print(v.Name, v.Value)
	end

	return ReturnEffects
end

if you need anymore context just let me know.

2 Likes