Module script returning nil, even tough variable is not nil

Hello, recently i came across an error in my script where the returned value from a module script’s function was nil. I did a few checks and saw that before returning the value, the module script prints the variable as false (expected behaviour).

I have tried looking into other topics in the devforum, none of them helped me.

Code:

Connection = RunService.Stepped:Connect(function()
							HasHitbox = PlacementHandler.UpdatePosition(UserInputService:GetMouseLocation())
end)
print(HasHitbox)

Sorry if the code is formated wrongly in the post, it is kinda weird to do that.

Any help is apreciated.

We will need to see both the script that calls the ModuleScript and the code of the ModuleScript itself, please.

Part of the module script.


	for i,v in pairs(workspace:GetPartsInPart(MainPlacementHandler.Preview.Hitbox), OverlapParam) do
		if v.Name == "Hitbox" then
			HasHitbox = true
		end
	end
	print(HasHitbox, "From module")
	if HasHitbox then --Tried to work my way around it, also did not work.
		return true
	else
		return false
	end
end

Can I see the whole thing, please?

function MainPlacementHandler.UpdatePosition(Position)
	local PositionToPlace = MainPlacementHandler.RaycastFromViewport(Position)
	
	local Angles = MainPlacementHandler.Preview:GetPivot().Rotation
	
	
	MainPlacementHandler.Preview:PivotTo(CFrame.new(MainPlacementHandler.AdvancedRound(PositionToPlace.X, 1), MainPlacementHandler.AdvancedRound(PositionToPlace.Y, 1), MainPlacementHandler.AdvancedRound(PositionToPlace.Z, 1)) * Angles)
	
	local HasHitbox = false
	local OverlapParam = OverlapParams.new()
	
	OverlapParam.FilterType = Enum.RaycastFilterType.Blacklist
	OverlapParam.FilterDescendantsInstances = {MainPlacementHandler.Preview}
	
	for i,v in pairs(workspace:GetPartsInPart(MainPlacementHandler.Preview.Hitbox), OverlapParam) do
		if v.Name == "Hitbox" then
			HasHitbox = true
		end
	end
	print(HasHitbox, "From module")
	if HasHitbox then --Tried to work my way around it, did not work.
		return true
	else
		return false
	end
end

Sorry for my bad scripting

I was able to fix the issue by manually yelding the thread for a few millseconds. Hope this helps anyways.